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.
STM32 UART+Circular Buffer+parity bit
Moderator: Benj
-
- Posts: 20
- Joined: Mon Jan 29, 2018 5:44 pm
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
STM32 UART+Circular Buffer+parity bit
- Attachments
-
- UART_testRC_parity_bit.fcfx
- (16.55 KiB) Downloaded 182 times
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: STM32 UART+Circular Buffer+parity bit
Hi,
I have not had chance to test this, but this C code in a C icon after the UART1::Initialise might work.
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);
-
- Posts: 20
- Joined: Mon Jan 29, 2018 5:44 pm
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
Re: STM32 UART+Circular Buffer+parity bit
Hi, Many thanks for it. I will add it soon, test with USB/UART conveter and write an information about result.
-
- Posts: 20
- Joined: Mon Jan 29, 2018 5:44 pm
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
Re: STM32 UART+Circular Buffer+parity bit
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.
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.
- Attachments
-
- UART_testRC_parity_bit.fcfx
- (16.22 KiB) Downloaded 205 times