2026-01-26 6:56 AM - last edited on 2026-01-26 7:00 AM by Andrew Neil
Hello guys.
I have an STM32WB5MM-DK disco board and im trying to get familiar with the ble stack. What i want to do is create a p2p server, poll an onboard i2c temp sensor for data and send that data through ble.
What i did at first (successfully)was to set the device as a p2p server, set the user button as an EXT line and set the irq to schedule a task. That task transfered a random number through ble.
What i tried to do next was to set the interrupt handler schedule a task tha would poll for the i2c data and schedule another task that would send said data, which didn't work. The address of the onboard i2c sensor is 0x70.
I attach my .ioc file
My callback function
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == B1_Pin)
{
UTIL_SEQ_SetTask(1U << TASK_BUTTON_1, CFG_SCH_PRIO_0);
}
APP_DBG_MSG(" Buttn press\n\r");
return;
}I've added the name of my tasks on the app_conf.h file
/**< Add in that list all tasks that may send a ACI/HCI command */
typedef enum
{
CFG_TASK_ADV_CANCEL_ID,
#if (L2CAP_REQUEST_NEW_CONN_PARAM != 0 )
CFG_TASK_CONN_UPDATE_REG_ID,
#endif
CFG_TASK_HCI_ASYNCH_EVT_ID,
/* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */
TASK_BUTTON_1,
TASK_CUSTOM_STS_T_NOTIFY,
/* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */
CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */
} CFG_Task_Id_With_HCI_Cmd_t;I've registered my tasks to notification functions
void Custom_APP_Init(void)
{
/* USER CODE BEGIN CUSTOM_APP_Init */
UTIL_SEQ_RegTask( 1U << TASK_BUTTON_1, UTIL_SEQ_RFU, Custom_Sts_t_Update_Char);
UTIL_SEQ_RegTask( 1U << TASK_CUSTOM_STS_T_NOTIFY, UTIL_SEQ_RFU, Custom_Sts_t_Send_Notification);
/* USER CODE END CUSTOM_APP_Init */
return;
}
And last but not least iimplemented teh notification functions
void Custom_Sts_t_Update_Char(void) /* Property Read */
{
uint8_t temp_buf[2];
if (HAL_I2C_Master_Receive(&hi2c3,
(0x71),
temp_buf,
2,
100) != HAL_OK)
{
return;
}
raw_temp = (int16_t)((temp_buf[1] << 8) | temp_buf[0]);
/* Sensor gives 0.01°C per LSB */
temp_centi = raw_temp/(float)100;
/* Schedule BLE notification */
UTIL_SEQ_SetTask(TASK_CUSTOM_STS_T_NOTIFY, CFG_SCH_PRIO_0);
}
void Custom_Sts_t_Send_Notification(void) /* Property Notification */
{
// temperature in 0.01°C
/* Combine bytes (LSB first) */
/* Pack data for BLE (little endian) */
NotifyCharData[0] = (uint8_t)(temp_centi & 0xFF);
NotifyCharData[1] = (uint8_t)(temp_centi >> 8);
/* Send notification */
Custom_STM_App_Update_Char(CUSTOM_STM_STS_T, NotifyCharData);
}I've built a simple python script so that the board connects to my pc through bl and subscribes to the characteristic for notifications, so something fails.
What is the best way to poll from data and trasnfer it through bl?
Any advice woud be welcomed