tomazj
tomazj

Reputation: 313

STM32WB50CG - Correct way to update value of characteristic

I have a question about how to correctly update a value of characteristic of custom BLE service on STM32WB50CG. The project was set up with CubeMX following their official tutorial: https://www.youtube.com/watch?v=i10X4Blr8ns.

My main application is running on M4 core. It uses multiple sensors and then does various statistics with data taken from them. BLE stack is running on M0+ core. I can see all the services & characteristics I defined in the app (BLE Toolbox from STM) on my Android phone. Now I am trying to figure out how to update characteristics from main application. I tried to call those functions bellow with predefined value in my main app, but read value of characteristic on my Android phone is always 0.

Result status of aci_gatt_update_char_value is "success" when Custom_STM_App_Update_Char is called.

Functions I tried to call in my main application on M4 core to update characteristics (with fixed value of 5 for testing purposes)

Custom_STM_App_Update_Char(CUSTOM_STM_CVOLTAGE, (uint8_t*)5);
Custom_STM_App_Update_Char(CUSTOM_STM_CCURRENT, (uint8_t*)5);

Example of two update value functions for my characteristics

case CUSTOM_STM_CVOLTAGE:
  result = aci_gatt_update_char_value(CustomContext.CustomVsHdle,
                                      CustomContext.CustomCvoltageHdle,
                                      0, /* charValOffset */
                                      SizeCvoltage, /* charValueLen */
                                      (uint8_t *)  pPayload);
  /* USER CODE BEGIN CUSTOM_STM_Service_1_Char_1*/

  /* USER CODE END CUSTOM_STM_Service_1_Char_1*/
  break;

case CUSTOM_STM_CCURRENT:
  result = aci_gatt_update_char_value(CustomContext.CustomCsHdle,
                                      CustomContext.CustomCcurrentHdle,
                                      0, /* charValOffset */
                                      SizeCcurrent, /* charValueLen */
                                      (uint8_t *)  pPayload);
  /* USER CODE BEGIN CUSTOM_STM_Service_3_Char_1*/

  /* USER CODE END CUSTOM_STM_Service_3_Char_1*/
  break;

Upvotes: 0

Views: 1343

Answers (1)

Amar Mahmutbegovic
Amar Mahmutbegovic

Reputation: 46

The first and most obvious issue with your code is that you are casting integer literal to the uint8_t address. Put the value in a variable on the stack and pass the address of that variable to Custom_STM_App_Update_Char.

Instead of: Custom_STM_App_Update_Char(CUSTOM_STM_CVOLTAGE, (uint8_t*)5);

do

uint8_t my_value = 5; Custom_STM_App_Update_Char(CUSTOM_STM_CVOLTAGE, &my_value);

Upvotes: 1

Related Questions