2018-05-11 05:07 AM
Hello,
I am trying to communicate with remote serial device which needs 7-bit data length, Even or odd parity, 1 stop bit. But I am facing problems in implementing this. Problem is the data received in RDR register is incorrect. For example I am transmitting 0x31 from PC terminal and I am getting 0xB1 when I configured UART with 8,E,1 and PC terminal with 7,E,1 setting.This seems wrong but its correct as STM32 has data word length including parity If seen the above byte in binary form : 0x31 is 00110001 and 0xB1 is 10110001 . Its clear that the latter is the 0x31 with added even parity. But I am not getting why RDR has 0xB1 instead of 0x31
after reception
? I am using STM32F091RCT6 with SWSTM32 IDE.The same was tested with odd parity too but with same results. Parity handling is done in STM32 isn't it? I have tried searching for user manual of this MCU but didn't find any, found only reference manual which didn't helped in knowing how STM32 handles parity. I have successfully tested the 8,E/O,1 combination and it worked fine, but 7,E/O,1 didn't worked. Any help will be appreciated.#stm32f-uartSolved! Go to Solution.
2018-05-13 11:05 PM
The latter probably gets masked as you handle chars (uint8_t) rather than what comes out of the RDR register (uint16_t), ST saves a bunch of gates in the USART design and you have to write uint8_t data = (uint8_t)(USART1->RDR & 0x7F);
2018-05-11 06:50 AM
The STM32 counts the parity bit in the settings, for 8E1 you need to configure 9-bit operation, of 7O1 you need 8-bit. You should also mask the data register on a read to the bits that carry the payload, and exclude the parity bit.
2018-05-13 10:57 PM
Hello Clive,
Yes the same configuration I used 8,E/O,1 works but the 7,E/O,1 don't. I thought parity handling is done on chip and software get the payload it needs because it worked for 8,E/O,1 , but it turns out that this needs to be handled in software.
2018-05-13 11:05 PM
The latter probably gets masked as you handle chars (uint8_t) rather than what comes out of the RDR register (uint16_t), ST saves a bunch of gates in the USART design and you have to write uint8_t data = (uint8_t)(USART1->RDR & 0x7F);