cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert received uint8_t array to string in stm32 ?

Aabc
Associate II

I am receiving data from UART in uint8_t array.

I want to convert array to string to work on it:

if (Received Data=="Reset") {  resetFunc();  }

if (Received Data.substring(0,8)=="ABCDASD")

{

Do something

 }

if (Received Data.substring(4,8)=="ABC1234")

{

 int Number=1234;         // convert substring to int

char Data ="ABC";         // convert substring to char

}

5 REPLIES 5
KnarfB
Principal III

You cannot compare strings in C.

You can cast (uint8_t*) to (char*) ans use strcmp thereafter.

hth

KnarfB

TDK
Guru
if (strcmp((const char *) Received Data, "Reset") == 0) {
  resetFunc();
}
if (strncmp((const char *) Received Data, "ABCDASD", 7) == 0) {
  Do something
}
if (strncmp((const char *) &Received Data[4], "ABC1234", 4) == 0) {
  ...
}

If you feel a post has answered your question, please click "Accept as Solution".

This is more a C language issue, and not STM32 specific

You can construct/re-construct a string a character at a time.

You might need to synchronize and discard characters if you receive from a serial port.

To use string functions you need to insure the data is NUL terminated.

Review C libraries and documentation. Review materials on parsing input.

For numeric conversion there are functions like atoi() and atod(), also sscanf()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Aabc
Associate II

Thanks for all.

Aabc
Associate II

It worked

Very thanks