cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Discovery, cannot clear parity error intterrupt

takeda
Associate
Posted on June 02, 2014 at 04:16

Hello,

I'm using STM32F4 discovery to develop usart communication function.

The usart parameter is below.

 /// Set serial port

 USART_StructInit(&USART_InitStructure);

 USART_InitStructure.USART_BaudRate = 9600;          ///< 9600bps

 USART_InitStructure.USART_WordLength = USART_WordLength_9b;      ///< data 8bit + parity 1bit

 USART_InitStructure.USART_StopBits = USART_StopBits_1;       ///< stop 1bit

 USART_InitStructure.USART_Parity = USART_Parity_Even;       ///< parity even

 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;     ///< enable Rx, Tx

 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; ///< no hardware flow control

 USART_Init(USART3, &USART_InitStructure); And enable PE interrupt, and then, send parity error data to this discovery board.

So, parity error interrupt is occurred successfully, but after this parity error intterupt is occured continuously (I cannot clear the PE error bit).

The USART intterrupt is below.

void USART3_IRQHandler (void) __irq

{

     char tmpRcv; 

 

     /// PE Interrupt  (PE flag is cleared when the flag is read) 

     if (USART_GetFlagStatus(USART3, USART_FLAG_PE) == SET)    

     {

     }

     /// RXNE interrupt

     else if (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)

     {

          ///receive data (and the RXNE flag is cleared)

          tmpRcv = USART_ReceiveData(USART3);

        ....

     }

It seems that the PE flag is not cleared when the flag is read.

Please help to solve this problem.

best regards.

#uart #stm32 #discovery #usart
3 REPLIES 3
takeda
Associate
Posted on June 02, 2014 at 06:03

Hello,

I modified the usart intterupt handler as below and it seems to work correct.

void USART3_IRQHandler (void) __irq

{

     char tmpRcv;

     /// RXNE interrupt

     if (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)

    {

          if (USART_GetFlagStatus(USART3, USART_FLAG_PE) != SET)

         {       

               ///receive data and clear RXNE interrupt flag

               tmpRcv = USART_ReceiveData(USART3);

         }

         else

        { 

               tmpRcv = USART_ReceiveData(USART3);

               USART_GetFlagStatus(USART3, USART_FLAG_PE);

        }

    }

}

Is this sequence is correct ?

And, I think this code is not simple, if there are other better code, please let me know.

best regards.

Posted on June 02, 2014 at 06:06

The PE is NOT cleared by reading the status, but rather reading the data register.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 02, 2014 at 06:22

#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
void USART3_IRQHandler(void)
{
if (USART_GetFlagStatus(USART3, USART_FLAG_ERRORS) == SET) 
{
USART_ReceiveData(USART3); // Discarded read to clear
}
/// RXNE interrupt
if (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
{
char tmpRcv; 
///receive data (and the RXNE flag is cleared)
tmpRcv = USART_ReceiveData(USART3);
....
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..