/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / [USART - Parity error] How to ?

Username:     
Password:     
             

Forum

# 1   2010-06-01 10:20:01 [USART - Parity error] How to ?

matmout
Member
From: Grenoble
Registered: 2010-05-10
Posts: 12

[USART - Parity error] How to ?

Hello, in my project, I would like to detect parity error in order to implement a retransmission protocol.

So, my USART interface is configured as below :

Code:

    // I set it to 9b instead of 8b: 8b (for ascii char) + 1 for parity calculation
    USART_InitStructure.USART_WordLength = USART_WordLength_9b;

    // I'm using IRDA, so according to the reference manual, it should be 1 stop bit
    USART_InitStructure.USART_StopBits = USART_StopBits_1;

    // I try to use this parity calculation
    USART_InitStructure.USART_Parity = USART_Parity_Even;

Then, I've an interrupt handler where when Primer2 receives something, it checks parity_error flag :

Code:

void USART1_IRQHandler(void)
{
    char c;

    //Received byte
    if (USART1->SR & USART_SR_RXNE)
    {
        /* Check for parity error */
        if ((USART1->SR & USART_SR_PE))
        {
            Clear_RxBuffer();
            RxBuffer[0] = 'E';
            RxBuffer[1] = 'R';
            RxBuffer[2] = '!';

            // Should I reset some flags ?
            //USART1->SR &= ~1;

            // If a parity error is detected, does primer2
            // asks for retransmission ???

            return;
        }
    
        c = IRDA_GetChar();
        RxBuffer[RxIndex] = c;
    
        RxIndex = (RxIndex+1)%MESSAGE_LENGTH;
    }

    ...

When my receiver detect a reception, what should I use : RXNE or IDLE ? I do not understand IDLE signal neither.

Is it the good way to detect parity error ?

Can you help me to understand how to implement retransmission in case of parity error ?

Last edited by matmout (2010-06-01 10:20:50)

Offline

 

# 2   2010-06-01 13:07:28 [USART - Parity error] How to ?

diabolo38
Member
Registered: 2010-03-12
Posts: 50

Re: [USART - Parity error] How to ?

i'm first not sure that RXNE flag will be set in case of error (parirty or over transmisonn error frame etc..) so you may have to consider testing USART1->SR & USART_SR_PE outside the RXNE if

for error retransmission you have somehow to inform the emiter that it need to resend the data and unfortunately for you the primer usart will not do anything on its own ... So you must build some higher  level s/w protocol on top of the uart h/w  data transfer.
for example once every 16 byte received  or on last data the receiver can acknowledge or not (nack) the transmitter (with packet crc/check sum for instance) so that the transmitter  will resend packet if incorrectly received ...note that parity errors is just able to detect a single bit error on a single data byte (parity 0x00=0 parity  0x03=0) where  packet crc are much more robust  than that.

Last  if you use the full uart lines you can use  RTS/CTS (Request to send) (Clear to send) h/w line to help  handling a simple byte after byte protocol ... but those are not available on irda ..

Offline

 

# 3   2010-06-01 13:24:28 [USART - Parity error] How to ?

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: [USART - Parity error] How to ?

RXNE will be set even when parity error is detected.
IDLE is dedicated to LIN support and used to inform all line units that bus is clear for use. I'm not sure how it applies to IRDA.

If you're not sure you are sending correct parity bits try to disable parity controll on receiver and perform checks manualy.

Code:

// Function for even parity
bool ParityCheck(uint32_t data) //put 9bit values from UARTx->DR here
{
    data ^= (data >> 4); //Some black magic
    data ^= (data >> 2);
    data ^= (data >> 1);
    if((data & 1) == (data >> 8)) 
        return true; //swap with 'false' for Odd parity
    else 
        return false;
}

Offline

 

# 4   2010-06-01 14:16:34 [USART - Parity error] How to ?

matmout
Member
From: Grenoble
Registered: 2010-05-10
Posts: 12

Re: [USART - Parity error] How to ?

Thank you, I'll try it tonight.

Offline

 

# 5   2010-06-03 13:47:18 [USART - Parity error] How to ?

ronald
New member
Registered: 2010-05-21
Posts: 5

Re: [USART - Parity error] How to ?

somebody can do it me the favor and tell me how I can configurate the primer2's
serials ports

Offline

 

# 6   2010-06-03 14:03:46 [USART - Parity error] How to ?

ronald
New member
Registered: 2010-05-21
Posts: 5

Re: [USART - Parity error] How to ?

or where i can find information about that thanks for yours comments

Offline

 

Board footer