cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8T6 UART 8-bits and Even parity

Yeswanth
Associate II

Hii

 

I am using STM32F103C8T6 controller. In this controller I am using the UART1 and UART2 transmitting and receiving data. In UART1 I adjust 9600 Baud rate, 8-data bits, None parity and 1 stop in these configuration I am transmitting and receiving data is good, But in UART2 I adjust 9600 Baud rate, 8-data bits, Even parity and 1 stop in these configuration I am transmitting and receiving garbage data.

Please help me to use the UART2 in these configurations.

1 ACCEPTED SOLUTION

Accepted Solutions

In the configuration parity is counted as a bit being transmitted 

So 8E1 is set as 9 bits and even parity

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

View solution in original post

4 REPLIES 4

In the configuration parity is counted as a bit being transmitted 

So 8E1 is set as 9 bits and even parity

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

If you only send ASCII characters, then 8,E,1 will work because you only need 7 bits. Then in  serial interface you set it up to receive 7,E,1. The 8th bit is the parity which should get set to zero by the serial interface.

But if you want to send data in full 8 bits or byte values greater than 0x7F, then you need to set up the STM32 as 9,E,1 so you get your full 8 bits + parity bit. The serial interface can be set up to receive as 8,E,1.

 

 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

@Tesla DeLorean wrote:

In the configuration parity is counted as a bit being transmitted 

So 8E1 is set as 9 bits and even parity


@Tesla DeLorean I believe you've meant to say 8E1 is set up as 7 bits and even parity.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

Perhaps I was inarticulate, but also not where I could paste in code. You do need to tell ST to send 9-bits so than the 8 data bits aren't junked.

Rest-of-World

8E1

ST

UartHandle.Init.WordLength = UART_WORDLENGTH_9B; // 8+Parity
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_EVEN;

 

Rest-of-World

7E1

ST

UartHandle.Init.WordLength = UART_WORDLENGTH_8B; // 7+Parity
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_EVEN;

and you probably want to mask the data pulled from the data register

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