2024-08-28 10:26 PM
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.
Solved! Go to Solution.
2024-08-28 11:21 PM
In the configuration parity is counted as a bit being transmitted
So 8E1 is set as 9 bits and even parity
2024-08-28 11:21 PM
In the configuration parity is counted as a bit being transmitted
So 8E1 is set as 9 bits and even parity
2024-08-29 12:45 AM
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.
2024-08-29 12:56 AM
@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.
2024-08-29 05:52 AM
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