Skip to main content
Associate
March 18, 2025
Question

Bluetooth Communication between two STM32WB55 not working

  • March 18, 2025
  • 3 replies
  • 1196 views

Communication between two STM32WB55 devices via Bluetooth is not working as expected. Device A (the client) cannot receive data from Device B (t

 

static SVCCTL_EvtAckStatus_t Event_Handler(void *Event)
{
SVCCTL_EvtAckStatus_t return_value;
hci_event_pckt *event_pckt;
evt_blecore_aci *blecore_evt;

P2P_Client_App_Notification_evt_t Notification;

return_value = SVCCTL_EvtNotAck;
event_pckt = (hci_event_pckt *)(((hci_uart_pckt*)Event)->data);

switch(event_pckt->evt)
{
case HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE:
{
blecore_evt = (evt_blecore_aci*)event_pckt->data;
switch(blecore_evt->ecode)
{

case ACI_ATT_READ_BY_GROUP_TYPE_RESP_VSEVT_CODE:
{
aci_att_read_by_group_type_resp_event_rp0 *pr = (void*)blecore_evt->data;
uint8_t numServ, i, idx;
uint16_t uuid, handle;

uint8_t index;
handle = pr->Connection_Handle;
index = 0;
while((index < BLE_CFG_CLT_MAX_NBR_CB) &&
(aP2PClientContext[index].state != APP_BLE_IDLE))
{
APP_BLE_ConnStatus_t status;

status = APP_BLE_Get_Client_Connection_Status(aP2PClientContext[index].connHandle);

if((aP2PClientContext[index].state == APP_BLE_CONNECTED_CLIENT)&&
(status == APP_BLE_IDLE))
{
/* Handle deconnected */

aP2PClientContext[index].state = APP_BLE_IDLE;
aP2PClientContext[index].connHandle = 0xFFFF;
break;
}
index++;
}

if(index < BLE_CFG_CLT_MAX_NBR_CB)
{
aP2PClientContext[index].connHandle= handle;

numServ = (pr->Data_Length) / pr->Attribute_Data_Length;

/* the event data will be
* 2bytes start handle
* 2bytes end handle
* 2 or 16 bytes data
* we are interested only if the UUID is 16 bit.
* So check if the data length is 6
*/
#if (UUID_128BIT_FORMAT==1)
if (pr->Attribute_Data_Length == 20)
{
idx = 16;
#else
if (pr->Attribute_Data_Length == 6)
{
idx = 4;
#endif
for (i=0; i<numServ; i++)
{
uuid = UNPACK_2_BYTE_PARAMETER(&pr->Attribute_Data_List[idx]);
if(uuid == P2P_SERVICE_UUID)
{
#if(CFG_DEBUG_APP_TRACE != 0)
APP_DBG_MSG("-- GATT : P2P_SERVICE_UUID FOUND - connection handle 0x%x \n", aP2PClientContext[index].connHandle);
#endif
#if (UUID_128BIT_FORMAT==1)
aP2PClientContext[index].P2PServiceHandle = UNPACK_2_BYTE_PARAMETER(&pr->Attribute_Data_List[idx-16]);
aP2PClientContext[index].P2PServiceEndHandle = UNPACK_2_BYTE_PARAMETER (&pr->Attribute_Data_List[idx-14]);
#else
aP2PClientContext[index].P2PServiceHandle = UNPACK_2_BYTE_PARAMETER(&pr->Attribute_Data_List[idx-4]);
aP2PClientContext[index].P2PServiceEndHandle = UNPACK_2_BYTE_PARAMETER (&pr->Attribute_Data_List[idx-2]);
#endif
aP2PClientContext[index].state = APP_BLE_DISCOVER_CHARACS ;
}
idx += 6;
}
}
}
}
break;

case ACI_ATT_READ_BY_TYPE_RESP_VSEVT_CODE:
{

aci_att_read_by_type_resp_event_rp0 *pr = (void*)blecore_evt->data;
uint8_t idx;
uint16_t uuid, handle;

/* the event data will be
* 2 bytes start handle
* 1 byte char properties
* 2 bytes handle
* 2 or 16 bytes data
*/

uint8_t index;

index = 0;
while((index < BLE_CFG_CLT_MAX_NBR_CB) &&
(aP2PClientContext[index].connHandle != pr->Connection_Handle))
index++;

if(index < BLE_CFG_CLT_MAX_NBR_CB)
{

/* we are interested in only 16 bit UUIDs */
#if (UUID_128BIT_FORMAT==1)
idx = 17;
if (pr->Handle_Value_Pair_Length == 21)
#else
idx = 5;
if (pr->Handle_Value_Pair_Length == 7)
#endif
{
pr->Data_Length -= 1;
while(pr->Data_Length > 0)
{
uuid = UNPACK_2_BYTE_PARAMETER(&pr->Handle_Value_Pair_Data[idx]);
/* store the characteristic handle not the attribute handle */
#if (UUID_128BIT_FORMAT==1)
handle = UNPACK_2_BYTE_PARAMETER(&pr->Handle_Value_Pair_Data[idx-14]);
#else
handle = UNPACK_2_BYTE_PARAMETER(&pr->Handle_Value_Pair_Data[idx-2]);
#endif
if(uuid == P2P_WRITE_CHAR_UUID)
{
#if(CFG_DEBUG_APP_TRACE != 0)
APP_DBG_MSG("-- GATT : WRITE_UUID FOUND - connection handle 0x%x\n", aP2PClientContext[index].connHandle);
#endif
aP2PClientContext[index].state = APP_BLE_DISCOVER_WRITE_DESC;
aP2PClientContext[index].P2PWriteToServerCharHdle = handle;
}

else if(uuid == P2P_NOTIFY_CHAR_UUID)
{
#if(CFG_DEBUG_APP_TRACE != 0)
APP_DBG_MSG("-- GATT : NOTIFICATION_CHAR_UUID FOUND - connection handle 0x%x\n", aP2PClientContext[index].connHandle);
#endif
aP2PClientContext[index].state = APP_BLE_DISCOVER_NOTIFICATION_CHAR_DESC;
aP2PClientContext[index].P2PNotificationCharHdle = handle;
}
#if (UUID_128BIT_FORMAT==1)
pr->Data_Length -= 21;
idx += 21;
#else
pr->Data_Length -= 7;
idx += 7;
#endif
}
}
}
}
break;

case ACI_ATT_FIND_INFO_RESP_VSEVT_CODE:
{
aci_att_find_info_resp_event_rp0 *pr = (void*)blecore_evt->data;

uint8_t numDesc, idx, i;
uint16_t uuid, handle;

/*
* event data will be of the format
* 2 bytes handle
* 2 bytes UUID
*/

uint8_t index;

index = 0;
while((index < BLE_CFG_CLT_MAX_NBR_CB) &&
(aP2PClientContext[index].connHandle != pr->Connection_Handle))

index++;

if(index < BLE_CFG_CLT_MAX_NBR_CB)
{

numDesc = (pr->Event_Data_Length) / 4;
/* we are interested only in 16 bit UUIDs */
idx = 0;
if (pr->Format == UUID_TYPE_16)
{
for (i=0; i<numDesc; i++)
{
handle = UNPACK_2_BYTE_PARAMETER(&pr->Handle_UUID_Pair[idx]);
uuid = UNPACK_2_BYTE_PARAMETER(&pr->Handle_UUID_Pair[idx+2]);

if(uuid == CLIENT_CHAR_CONFIG_DESCRIPTOR_UUID)
{
#if(CFG_DEBUG_APP_TRACE != 0)
APP_DBG_MSG("-- GATT : CLIENT_CHAR_CONFIG_DESCRIPTOR_UUID- connection handle 0x%x\n", aP2PClientContext[index].connHandle);
#endif
if( aP2PClientContext[index].state == APP_BLE_DISCOVER_NOTIFICATION_CHAR_DESC)
{

aP2PClientContext[index].P2PNotificationDescHandle = handle;
aP2PClientContext[index].state = APP_BLE_ENABLE_NOTIFICATION_DESC;

}
}
idx += 4;
}
}
}
}
break; /*ACI_ATT_FIND_INFO_RESP_VSEVT_CODE*/

case ACI_GATT_NOTIFICATION_VSEVT_CODE:
{
aci_gatt_notification_event_rp0 *pr = (void*)blecore_evt->data;
uint8_t index;

index = 0;
while((index < BLE_CFG_CLT_MAX_NBR_CB) &&
(aP2PClientContext[index].connHandle != pr->Connection_Handle))
index++;

if(index < BLE_CFG_CLT_MAX_NBR_CB)
{

if ( (pr->Attribute_Handle == aP2PClientContext[index].P2PNotificationCharHdle) &&
(pr->Attribute_Value_Length == (2)) )
{

Notification.P2P_Client_Evt_Opcode = P2P_NOTIFICATION_INFO_RECEIVED_EVT;
Notification.DataTransfered.Length = pr->Attribute_Value_Length;
Notification.DataTransfered.pPayload = &pr->Attribute_Value[0];

Gatt_Notification(&Notification);

/* INFORM APPLICATION BUTTON IS PUSHED BY END DEVICE */

}
}
}
break;/* end ACI_GATT_NOTIFICATION_VSEVT_CODE */

case ACI_GATT_PROC_COMPLETE_VSEVT_CODE:
{
aci_gatt_proc_complete_event_rp0 *pr = (void*)blecore_evt->data;
#if(CFG_DEBUG_APP_TRACE != 0)
APP_DBG_MSG("-- GATT : ACI_GATT_PROC_COMPLETE_VSEVT_CODE \n");
APP_DBG_MSG("\n");
#endif

uint8_t index;

index = 0;
while((index < BLE_CFG_CLT_MAX_NBR_CB) &&
(aP2PClientContext[index].connHandle != pr->Connection_Handle))
index++;

if(index < BLE_CFG_CLT_MAX_NBR_CB)
{

UTIL_SEQ_SetTask( 1<<CFG_TASK_SEARCH_SERVICE_ID, CFG_SCH_PRIO_0);

}
}
break; /*ACI_GATT_PROC_COMPLETE_VSEVT_CODE*/
default:
break;
}
}

break; /* HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE */

default:
break;
}

return(return_value);
}/* end BLE_CTRL_Event_Acknowledged_Status_t */

3 replies

Andrew Neil
Super User
March 20, 2025

welcome to the forum.

Please give details of your setup, tools, what debugging you've tried, etc:

See: How to write your question to maximize your chances to find a solution

Also: How to insert source code

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
li4Author
Associate
March 24, 2025

为什么在以下日志之后 ECODE 更改为 0xc11:ECODE: 0xc0a, ECODE: 0xc0a, -- GATT: P2P_SERVICE_UUID FOUND - 连接句柄 0x801, aP2PClientContext[index].P2PServiceHandle 0xc,aP2PClientContext[index].P2PServiceEndHandle 0x11?


Google translate:

Why does ECODE change to 0xc11 after the following logs: ECODE: 0xc0a, ECODE: 0xc0a, -- GATT: P2P_SERVICE_UUID FOUND - Connection handle 0x801, aP2PClientContext[index].P2PServiceHandle 0xc, aP2PClientContext[index].P2PServiceEndHandle 0x11?

li4Author
Associate
March 24, 2025

li4_0-1742788800542.pngli4_1-1742788819091.pngli4_2-1742788831763.png

li4_3-1742788849106.png

/* USER CODE BEGIN APP_BLE_Init_2 */
UTIL_SEQ_SetTask(1 << CFG_TASK_START_SCAN_ID, CFG_SCH_PRIO_0);
/* USER CODE END APP_BLE_Init_2 */

case AD_TYPE_MANUFACTURER_SPECIFIC_DATA: /* Manufacturer Specific */
/* USER CODE BEGIN AD_TYPE_MANUFACTURER_SPECIFIC_DATA */

/* USER CODE END AD_TYPE_MANUFACTURER_SPECIFIC_DATA */
if (adlength >= 7 && adv_report_data[k + 2] == 0x01)
{ /* ST VERSION ID 01 */
APP_DBG_MSG("--- ST MANUFACTURER ID --- \n\r");
// switch (adv_report_data[k + 3])
// { /* Demo ID */
// case CFG_DEV_ID_P2P_SERVER1: /* End Device 1 */
APP_DBG_MSG("-- SERVER DETECTED -- VIA MAN ID\n\r");
BleApplicationContext.DeviceServerFound = 0x01;
SERVER_REMOTE_ADDR_TYPE = 0x00;
SERVER_REMOTE_BDADDR[0] = 0x14;
SERVER_REMOTE_BDADDR[1] = 0x24;
SERVER_REMOTE_BDADDR[2] = 0x00;
SERVER_REMOTE_BDADDR[3] = 0xE1;
SERVER_REMOTE_BDADDR[4] = 0x80;
SERVER_REMOTE_BDADDR[5] = 0x02;
// break;

// default:
// break;
// }
}
break;

li4Author
Associate
March 24, 2025

li4_4-1742788973099.pngli4_5-1742788986325.pngli4_6-1742788999409.pngli4_7-1742789011906.pngli4_8-1742789022157.png

** CREATE CONNECTION TO SERVER **

 

 

 

** CONNECTION COMPLETE EVENT WITH SERVER

 

 

 

** GATT SERVICES & CHARACTERISTICS DISCOVERY

 

* GATT : Start Searching Primary Services

 

ECODE: 0xc0a

ECODE: 0xc0a

-- GATT : P2P_SERVICE_UUID FOUND - connection handle 0x801

aP2PClientContext[index].P2PServiceHandle 0xc

aP2PClientContext[index].P2PServiceEndHandle 0x11

ECODE: 0xc11  

Andrew Neil
Super User
March 24, 2025

Again, please see How to insert source code.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
li4Author
Associate
March 25, 2025
#if (OOB_DEMO == 0)
 /**
 * Start scanning
 */
 UTIL_SEQ_SetTask(1 << CFG_TASK_START_SCAN_ID, CFG_SCH_PRIO_0);
#endif
 /* USER CODE BEGIN APP_BLE_Init_2 */
 UTIL_SEQ_SetTask(1 << CFG_TASK_START_SCAN_ID, CFG_SCH_PRIO_0);
 /* USER CODE END APP_BLE_Init_2 */
 return;static void Connect_Request(void)
{
 /* USER CODE BEGIN Connect_Request_1 */
	uint8_t paddr[]={0x14,0x24,0x00,0xE1,0x80,0x02};
 /* USER CODE END Connect_Request_1 */
 tBleStatus result;

 APP_DBG_MSG("\r\n\r** CREATE CONNECTION TO SERVER ** \r\n\r");

 if (BleApplicationContext.Device_Connection_Status != APP_BLE_CONNECTED_CLIENT)
 {
 result = aci_gap_create_connection(SCAN_P,
 SCAN_L,
 SERVER_REMOTE_ADDR_TYPE, paddr,
 CFG_BLE_ADDRESS_TYPE,
 CONN_P1,
 CONN_P2,
 0,
 SUPERV_TIMEOUT,
 CONN_L1,
 CONN_L2);

 if (result == BLE_STATUS_SUCCESS)
 {
 /* USER CODE BEGIN BLE_CONNECT_SUCCESS */

 /* USER CODE END BLE_CONNECT_SUCCESS */
 BleApplicationContext.Device_Connection_Status = APP_BLE_LP_CONNECTING;

 }
 else
 {
 /* USER CODE BEGIN BLE_CONNECT_FAILED */

 /* USER CODE END BLE_CONNECT_FAILED */
 BleApplicationContext.Device_Connection_Status = APP_BLE_IDLE;

 }
 }
 /* USER CODE BEGIN Connect_Request_2 */

 /* USER CODE END Connect_Request_2 */
 return;
}