cancel
Showing results for 
Search instead for 
Did you mean: 

(Cubelde) I want to send uint8_t array and float variable with hal_uart_transmit. How can I do

ASwit.1
Associate

I've tried things but I don't understand the exact logic l.

4 REPLIES 4

Use HAL_UART_Transmit() casting a pointer to the variable or array to (uint8_t *) and describing the size of it.

Basic C coding

float myarray[8];

HAL_UART_Transmit(&hUart2, (uint8_t *)myarray, sizeof(myarray), SOMETIMEOUT);

HAL_UART_Transmit(&hUart2, (uint8_t *)&myarray[0], sizeof(myarray), SOMETIMEOUT);

These things are just collections of bytes, review Data Representation if you are unfamiliar with how computers hold data in memory or files.

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

I have to learn how to send data in all data types. eg: float, string, byte, uint8_t array. Can you suggest a resource to me

K&R ?

char string[] = "Hello\r\n";

HAL_UART_Transmit(&hUart2, (uint8_t *)string, strlen(string), SOMETIMEOUT);

float flt = 123.45f;

HAL_UART_Transmit(&hUart2, (uint8_t *)&flt, sizeof(flt), SOMETIMEOUT);

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

Float as a string

char string[16];

float flt = 123.45f;

HAL_UART_Transmit(&hUart2, (uint8_t *)string, sprintf(string,"%lf",flt), SOMETIMEOUT);

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