0

I am programming an STM32WB board using the following tutorial (https://www.youtube.com/watch?v=Zgw3wRpGSRQ&list=PLnMKNibPkDnG9JRe2fbOOpVpWY7E4WbJ-&index=18&ab_channel=STMicroelectronics)

I am able to send a hex value to the phone using the ST BLE Toolbox, however I would like to send a char to start, end goal would be to send a string. how could I go about displaying the hex value as a char?

Would CHAR_PROP_BROADCAST or CHAR_PROP_READ be more appropriate for this? I could not find any tutorials on this unfortunately.

enter image description here

followed this tutorial. https://www.youtube.com/watch?v=Zgw3wRpGSRQ&list=PLnMKNibPkDnG9JRe2fbOOpVpWY7E4WbJ-&index=18&ab_channel=STMicroelectronics

the tutorial only sends one hex number, to send more you can change the "Value length" on CubeMX, UpdateCharData[n] = some_data;

1 Answers1

0

You need to understand how a character is stored in the microcontroller/PC memory. Read about ASCII table. For example:

#include <stdio.h>
    int main() {
        unsigned num = 0x41; // two byte variable 
        printf("%0x\n", num);// output: 41
        printf("%d\n", num);// output: 65 
        printf("%c\n", num);// output: A 
        //because ASCII code 65 it's 'A' character
        return 0;
    }

As you can see, the same data are interpreted differently.

If you want to convert a integer to a character, just do the following ->

int a = 65;
char c = (char) a;

Or you can use itoa() function to convert the integer to a string.

simon_lee
  • 16
  • 5
  • The issue isn't on the microcontroller, the data is sent in bytes similar how uart is received. the issue is the conversion on the BLE phone app. currently it is displayed as hex as that allows interpretation. Seems I just have to write a phone app to display char. was hoping for ST to have a phone example – Shahin Haque Dec 12 '22 at 12:49