Skip to main content
werner_f
Associate II
September 9, 2023
Solved

STM32WB BLE - Update Char from main.c

  • September 9, 2023
  • 4 replies
  • 3106 views

Hello,

I'm pretty new in working with STM32WB-Chips and trying to implement a BLE-Application.

I am using a STM32WB55 Chip and for initial steps I created a project using Cube IDE and a Custom Template according to ST's "Getting Started" - Series on YouTube (https://www.youtube.com/watch?v=CKYWy7LKL68&list=PLnMKNibPkDnG9JRe2fbOOpVpWY7E4WbJ-&index=16).
This works in general and I can read and write characteristics using the BLE Toolbox App on my smartphone.

Now I want to update a characteristic value from my main-function, e.g. to distribute new sensor data via BLE.
I added the needed header files in my main and try to call the functions 
Custom_STM_App_Update_Char() or aci_gatt_update_char_value().The compiler gives me no warnings or errors, but calling this functions in the main loop leads to a HardFault during runtime.
Stepping into showed that the HardFault occurs after calling the 
static void SendCmd()-function probably.

Calling this functions from custom_stm.c works fine, e.g. if I am calling it in an Event_Handler after a read access there. So probably some parameters in my main.c are missing.

Problably I am just doing something stupidly wrong and don't get it. So how can i easilly update a characteristic value from a main function if new data is available?


Many thanks in advance :)



This topic has been closed for replies.
Best answer by Issamos

Hello @werner_f 

The easiest way is to replace the message that the program is already sending by the data you want to send. By : 

  • Creating a variable in main.h this variable will always  receive the data in the main.c (include main.h first)
  • Call this variable in the sending function in the ble_app (after including main.h to ble_app.c too).

Best regards .

II

4 replies

Issamos
IssamosBest answer
Super User
September 9, 2023

Hello @werner_f 

The easiest way is to replace the message that the program is already sending by the data you want to send. By : 

  • Creating a variable in main.h this variable will always  receive the data in the main.c (include main.h first)
  • Call this variable in the sending function in the ble_app (after including main.h to ble_app.c too).

Best regards .

II

werner_f
werner_fAuthor
Associate II
September 9, 2023

Thank you, like this I can now transfer my own data using the BLE stack.

But I want to run my code in server mode and want to send a notification to the client(smartphone) everytime new data occurs. How can I trigger this event from my main code? Just updating the buffer seems not to be enough. 

Right now, I am calling the update_char() function in my ble_app.c everytime an event occurcs, i.e. if the client reads a characteristic it is getting updated. This works fine. But I want to notify the client that new data is available without the client asking for it.

Issamos
Super User
September 9, 2023

Hello again @werner_f 

Happy to now about your progress.

I suggest you to close this post by choosing a best answer and ask your second question in a new post to give it more visibility. Personally, I'm not understanding your new request.

Best regards.

II