AnsweredAssumed Answered

UART, problem with Parity bit implementation

Question asked by kumar.rachit.001 on Mar 27, 2015
Latest reply on Mar 27, 2015 by Clive One
Hello,

I am setting up communication via Modbus over RS232 line. The implementation works fine when no parity is implemented. But the specification dictates that even parity should be supported.
The data reception is facilitated via DMA.
To support the parity, I added the parity configuration. The word length is currently set to 8 bits. I receive the data correctly when parity is ON, but it sets a partiy error and I presume that my controller doesn't transmit the response because,
1. Party error is set
2. It does not insert the paity bit correctly and my terminal doesn't understand the received data and I get no result.

I then looked further in the reference manual, and came across,

Table 145. Frame formats
M bit| PCE bit   | USART frame
0       |  0            | SB | 8 bit data | STB |
0       |  1            | SB | 7-bit data | PB | STB |
1       |  0            | SB | 9-bit data | STB |
1       |  1            | SB | 8-bit data PB | STB |

Legends: SB: start bit, STB: stop bit, PB: parity bit.

M bit is 0 for 8bit data length, 1 for 9bit data length
PCE is 0 for parity disabled, 1 for parity enabled

This means that I should set my word length to 9 bits in order to accomodate the parity bit, alongwith 8 data bits. But with this setting, my controller doesn't receive any data at all.

I checked the osci, and it shows the bits correctly, i.e, |SB|8 Data Bits|PB|STB|

Does anybody have any idea how/what may be causing a problem here?

The configuration module looks like,

USART_InitStructure.USART_BaudRate = p_baudrate;
if(p_parity == 0)
    USART_InitStructure.USART_WordLength = p_wordlength;
else
    USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = p_stopbits;
USART_InitStructure.USART_Parity = (U16)((U16)p_parity<<8);
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init((USART_TypeDef *) USART_BASE, &USART_InitStructure);

Note: This configuration works for both Rx and Tx with no parity selected. So the pin and DMA configurations are correct.

Outcomes