cancel
Showing results for 
Search instead for 
Did you mean: 

Sent int32_t with Hal_UART

Nmo.1
Associate III

Hi All,

  

I would like to send int32_t decimal number via USART, but with HAL_Uart_Transmit we can send uint_8.

Do you have any idea how I can do that?

Thanks.

3 REPLIES 3
TDK
Guru

HAL_UART_Transmit sends bytes. Whatever you have in those bytes it will send.

If you want to send binary data, convert the pointer and send.

int32_t x = 67;
HAL_UART_Trasmit(&huart1, (uint8_t *) &x, 4, HAL_MAX_DELAY);

If you want to send text data, convert it to a string and send.

int32_t x = 67;
char buffer[20];
sprintf(buffer, "%d", x);
HAL_UART_Trasmit(&huart1, (uint8_t *) buffer, strlen(buffer), HAL_MAX_DELAY);

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

Thank you so much.

It works for positive values. But I have still a problem with negative values. I can't send them because Hal_Uart_Transmit sends unsigned values.(uint8_t)

As I said before, it sends bytes. How you interpret that is up to the receiving side.
If you feel a post has answered your question, please click "Accept as Solution".