Skip to main content
Associate II
August 29, 2024
Solved

STM32F103C8T6 UART 8-bits and Even parity

  • August 29, 2024
  • 4 replies
  • 1446 views

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.

This topic has been closed for replies.
Best answer by Tesla DeLorean

In the configuration parity is counted as a bit being transmitted 

So 8E1 is set as 9 bits and even parity

4 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
August 29, 2024

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Principal
August 29, 2024

@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.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Tesla DeLorean
Guru
August 29, 2024

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Principal
August 29, 2024

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.

 

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source