cancel
Showing results for 
Search instead for 
Did you mean: 

Rx interrupt showing frame error

kunal5959
Associate II
Posted on February 28, 2013 at 16:54

I have to receive a data on my stm32f100 microcontroller which is sent from a software on PC through RS232 port. I am using IAR C compiler and in the interrupt handler i have some further sensor related program .Hope it is not confusing. This data is an information about an optical sensor attached to the microcontroller. The fixed timed sequence tobe sent from PC is as follows :

F8 FE A2 00 80F8 FE A2 00 80F8 FE A2 00 80 (Hex values) I have to make an interruopt routine such that it receives the above sent data and as soon as it receives ''A2'' the software returns to main program where corresponding SENSOR data is sent back using transmit interrupt. Now i have made the interrupt handler where the interrupt is called everytime there a data arrives at the serial port . Through debug i see the data arriving correctly to my microcontroller but i see that always there is an frame error or overrun error .I want these error to be removed. I have following setting for USART:- Parity-Even Stop bit-1 Baud rate 38400 Data bit -8 bit Hardware control -None USART_Mode=USART_Mode_Rx | USART_Mode_Tx; Can anyone tell me what could be the reason for the frame error or overrun error? and how can i remove it?.

void USART1_IRQHandler(void)
{
//RxInterrupt
USART_ClearITPendingBit(COM_USART,USART_IT_RXNE );
UINT8_T rxData = USART_ReceiveData(COM_USART);
if (rxData==0xA2) {
pal_test1_on();
pal_test1_off();
} 
// errors don't have to be indicated, they will be discarded anyway...
// iolDevice.DL.Message_handler.PL_Transfer_ind(rxData, PL_FRAMING_ERROR);
if((USART_GetFlagStatus(COM_USART, USART_FLAG_FE) ||
(USART_GetFlagStatus(COM_USART, USART_FLAG_ORE) ||
(USART_GetFlagStatus(COM_USART, USART_FLAG_PE)))))
{
rxData= ( UINT8_T)(USART1->SR & ( UINT8_T)0xFF); //read status
//then read data register ...
rxData = ( UINT8_T)(USART1->DR & ( UINT8_T)0xFF);
}
else
{ 
//IO-Link now wants some attention
pal_eRequestState = PAL_IOLSTATE_ACTIVE_REQUEST;
//when not in COMx-Mode, send WakeUp-Request
if (pal_eMode != IOL_PL_MODE)
{
iolDevice.DL.DL_mode_handler.PL_WakeUp_ind();
}
#if IOL_PAL_RX_USES_POLLING == 1
RxBuffer[RxBufferInpos] = rxData;
RxBufferInpos = (RxBufferInpos + 1) & RXBUF_MASK;
#else
iolDevice.PL.receiveByte(rxData);
#endif
}
}

3 REPLIES 3
Posted on February 28, 2013 at 19:09

I would not attempt to clear the RXNE interrupt, reading DR will do that.

I would not blindly read the DR, this will lose any status the SR might be reporting.

Be careful about what you call under interrupt, especially if it takes a long time, blocks, or writes/erases flash. These will cause overflow issues.

Framing errors might also occur if the baud rate/crystal/pll are generating less than ideal clocks, or the sender is not clocking the data at ideal rates. You should use a scope and confirm the observed bit timing.

Try using additional stop bits to increase the inter-symbol gap.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kunal5959
Associate II
Posted on March 04, 2013 at 11:48

I would not attempt to clear the RXNE interrupt, reading DR will do that.'' do you mean the

USART_ClearITPendingBit(COM_USART,USART_IT_RXNE 

''I would not blindly read the DR, this will lose any status the SR might be reporting.'' I am not worried about losing status because i always use my debugger to read the status register when any data is received.

''Be careful about what you call under interrupt, especially if it takes a long time, blocks, or writes/erases flash. These will cause overflow issues.'' How to detect if it is an overflow issue?

''Framing errors might also occur if the baud rate/crystal/pll are generating less than ideal clocks, or the sender is not clocking the data at ideal rates. You should use a scope and confirm the observed bit timing.'' I have checked the baud rate and it is exactly 384600 which is right.

''Try using additional stop bits to increase the inter-symbol gap.'' I cannot change the stop bits because the data is sent by a software whose functions are fixed and cannot be altered.

I would be glad if you can help me further.

Posted on March 04, 2013 at 13:21

I've posted USART examples

If using parity, make sure to program the USART in 9-bit mode. ie 8+1
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..