Page 1 of 1

STM32 UART+Circular Buffer+parity bit

Posted: Mon Feb 10, 2020 11:54 am
by dionyzoz
Hello.
Maybe my topic isn't new, because I want to fix parity bit in my application, but I need some help to solve the problem correctly. Benji wrote a little abut that in older posts. Port settings should be modified to 9-bit, but also adding some calculations are necessary. Because I'm using circular buffer to receive data, should I change it to 16bit? There are 2 optons: 8bit or 16bit. Maybe only 8 bits should be put into the buffer. Could someone modify added simple source code? It will be very helpful not only for me I think. Base code ralize 9600, 8-bit,no parity. I'm trying to realize 9600, 8-bit, parity ->even. UART macro have no possibility to check even, odd or no parity bit.
Thanks for any help in that point.

Re: STM32 UART+Circular Buffer+parity bit

Posted: Mon Feb 10, 2020 12:38 pm
by LeighM
Hi,
I have not had chance to test this, but this C code in a C icon after the UART1::Initialise might work.

Code: Select all

HAL_UART_DeInit(&MX_UART_NUMBER_1);
MX_UART_NUMBER_1.Init.Parity = UART_PARITY_EVEN;
HAL_UART_Init(&MX_UART_NUMBER_1);

Re: STM32 UART+Circular Buffer+parity bit

Posted: Mon Feb 10, 2020 1:11 pm
by dionyzoz
Hi, Many thanks for it. I will add it soon, test with USB/UART conveter and write an information about result.

Re: STM32 UART+Circular Buffer+parity bit

Posted: Mon Feb 10, 2020 8:27 pm
by dionyzoz
Hello,
Everything is clear.
First UART data bits shoud be set to 9.
Next your C code shoud be paste after the UART1::Initialise

For EVEN mode:
HAL_UART_DeInit(&MX_UART_NUMBER_1);
MX_UART_NUMBER_1.Init.Parity = UART_PARITY_EVEN;
HAL_UART_Init(&MX_UART_NUMBER_1);

For ODD mode:
HAL_UART_DeInit(&MX_UART_NUMBER_1);
MX_UART_NUMBER_1.Init.Parity = UART_PARITY_ODD;
HAL_UART_Init(&MX_UART_NUMBER_1);

I tested it on my application and also on STM32F0308 Discovery. Transmited data(I connect it by USB/UART converter) was checked on RealTerm 1.99.0.27 Everything works well. Here is a working example.
Thank you very much LeighM.