Skip to main content
Nmo.1
Associate III
December 24, 2021
Question

Sent int32_t with Hal_UART

  • December 24, 2021
  • 1 reply
  • 1839 views

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.

This topic has been closed for replies.

1 reply

TDK
December 24, 2021

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
Nmo.1Author
Associate III
December 24, 2021

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)

TDK
December 24, 2021
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""."