2025-05-20 12:20 AM
Hi, I want to send data and receive commands through BLE. For that, I followed some tutorials where I learned how to generate code using STM32CubeIDE. I can now see my device name in the BLE scanner, but I also want to send data and receive commands. I need to write some code for this. Can someone help me with where to write the code? For now, I just want to send some random data like 0x9944. I am using stm32wb55cgu6 board
2025-05-20 5:14 AM
Hello,
you could start with BLE_Custom example.
Once you're connected with your phone (ST BLE Toolbox app), you can send "0001" to turn on the LED and "0000" to turn it off (P2P WRITE). Please check the custom_app.c file where you can find how the LED toggling is done.
Also, this material below could be helpful.
How to build wireless applications with STM32WB MCUs - Application note
Please don't hesitate to ask further if you have any question.
Best regards,
ST support
2025-05-21 3:56 AM
Actually, i ahve followed https://www.youtube.com/watch?si=sCJTNwOABuTlPfP7&v=Zgw3wRpGSRQ&feature=youtu.be
this video .
what I'm working on involves using multiple ADCs with my mcu stm32wb55cgu6. Earlier, I was printing the data to the serial monitor via USB. Now, I want to use BLE instead of serial print. In main.c, I have done some calculations and all the initialization steps.
After using this tutorial, I saw that data is sent using a button press. But when I try to send the data directly from the main function, either it goes to the" void HardFault_Handler()" or the value is not advertised.
2025-05-21 5:03 AM
Hello,
would it be possible to share the project?
Best regards,
ST support
2025-05-21 5:26 AM
I used STM32Cube IDE and generated the basic code from a tutorial. For now, I am just trying to send 0x32. If it works, then I will add the rest of the code with the ADC.
In app_conf.h, I declared...
//function
void myTask(void);
// add CFG_TASK_MY_TASK
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 */
CFG_TASK_MY_TASK,
/* 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;
at app_ble.c inside void APP_BLE_Init(void)
// Add
UTIL_SEQ_RegTask(1<<CFG_TASK_MY_TASK,UTIL_SEQ_RFU,myTask);
UTIL_SEQ_SetTask(1<<CFG_TASK_MY_TASK,CFG_SCH_PRIO_0);
at custom_app.c
//define the same function
void myTask(void)
{
UpdateCharData[0] = 0x32;
Custom_Mycharnotify_Update_Char();
}
In main.c
while (1)
{
/* USER CODE END WHILE */
MX_APPE_Process();
HAL_Delay(1000);
UTIL_SEQ_SetTask(1<<CFG_TASK_MY_TASK,CFG_SCH_PRIO_0);
/* USER CODE BEGIN 3 */
}
2025-05-21 5:35 AM
2025-05-21 6:57 AM
Please don't add any code in main while loop, there should be only MX_APPE_Process().
You're probably getting a hardfault because you're setting the task before it is registered in the sequencer.
(APP_BLE_Init() needs to be called first) I recommend having a look at this document.
How to build wireless applications with STM32WB MCUs - Application note
For sending data periodically, please try to use timer server. Also, BLE_Heartrate example could help you to better understand.
Best regards,
ST support
2025-05-21 10:57 AM
Thank you, sir, for clearing my doubt. But the thing is, when I will add the ADC, it will work over SPI, and I will read the value in main.c inside the while loop. To send the ADC value, I need to call some function apart from MX_APPE_Process().
Can you please share a project or example code, if possible, that sends 2–3 different values over BLE at some interval?
Example:
// In loop
send(0x12);
HAL_Delay(1000);
send(0x4B);
HAL_Delay(1000);
send(0xA8);
HAL_Delay(1000);
2025-05-22 12:26 AM
Hello,
for this case, you could create tasks which will do ADC measurements and then you could periodically run them with timer server. As I mentioned before, if you look at the BLE_Heartrate example, you can get better understanding how it can be done. In the hrs_app.c file, it will register a task for measurement.
UTIL_SEQ_RegTask( 1<< CFG_TASK_MEAS_REQ_ID, UTIL_SEQ_RFU, HRSAPP_Measurement );
Then it creates a timer for periodic measurement. Once the timer is created, you can run it with certain interval.
HW_TS_Create(CFG_TIM_PROC_ID_ISR, &(HRSAPP_Context.TimerMeasurement_Id), hw_ts_Repeated, HrMeas);
HRSAPP_MEASUREMENT_INTERVAL (1000000/CFG_TS_TICK_VAL)
Please let me know, if it helps with your project.
Best regards,
ST support
2025-05-22 10:21 PM - edited 2025-05-22 11:11 PM
thank you sir