cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Transmit sends extra '00' between each byte

deep_rune
Associate III

This is probably a simple question but I can't find a reason for it - Im using the USART on a stm32L412 and I am sending 3 bytes

uint16_t SendDataOn[3]={0x90,0x3C,0x3E};

 HAL_UART_Transmit(&huart1,(uint8_t*)SendDataOn,3, 100)

Except when I send this, I get an extra byte between so it means I end up getting 0x90,0x00,0x3C instead of 0x90,0x3c,0x3E. When I increase the number of bytes to send to 5, I get 0x90,0x00,0x3C 0x00,0x3C

how do i set the USART so I don't get the 00 inbetween bytes?

4 REPLIES 4

> uint16_t SendDataOn[3]={0x90,0x3C,0x3E};

This means, in memory, each value is stored as a halfword, i.e. 2 bytes of which the upper one is 0x00. The transmission function then transmits all that, byte by byte.

JW

>>how do i set the USART so I don't get the 00 inbetween bytes?

Use a BYTE array, not a 16-BIT WORD array

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

ah nuts should have known

thanks

Pavel A.
Evangelist III

The HAL library uses uint16_t as the data type when the UART is in 9 bit mode and uint8_t otherwise.