cancel
Showing results for 
Search instead for 
Did you mean: 

USART with 7 data bits

Evgeniy Vasyliev
Associate III

Hi all!

I am using STM32F427 with HAL. I have to communicate with other devices using communication protocol over RS-232 interface (USART). The protocol is using 7 data bits, odd parity. I am struggling to make it work.

There is a setting for WordLength with 2 options:

- UART_WORDLENGTH_8B

- UART_WORDLENGTH_9B

But how to set it be equal to 7 data bits?

Here is USART configuration:

// Initialize communication settings

// Communication Parameters: 7 Data, 1 Stop, Odd Parity

// USART Receiver: On

// USART Transmitter: On

// TX, RX interrupts: enabled

// USART Mode: Asynchronous

huart.Init.WordLength = UART_WORDLENGTH_8B;

huart.Init.StopBits = UART_STOPBITS_1;

huart.Init.Parity = UART_PARITY_ODD;

huart.Init.Mode = UART_MODE_TX_RX;

huart.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart.Init.OverSampling = UART_OVERSAMPLING_16;

Seems that it is not working.

Can anyone suggest some solution please?

2 REPLIES 2

>>Seems that it is not working.

Not working how specifically?

You might have to mask the lower 7-bits on the USART->DR read, but the 8-bit mode means 7+1 as the parity bit is included in the budget.

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