cancel
Showing results for 
Search instead for 
Did you mean: 

USART escape sequence and interrupt.

tonyyu
Associate II
Posted on September 05, 2013 at 18:30

Hi,

I am using

STM324x9I-EVAL, which has a 32F439 chip with Keil tools chain and StdPeriph Lib, 1.2RC2, FreeRTOS 7.5.

The following is the section of interrupt code.

void USART1_IRQHandler(void)

{

  portBASE_TYPE higherPriorityTask;

  

  if(USART_GetITStatus(EVAL_COM1, USART_IT_RXNE) != RESET)

  {

    // Read one byte from the receive data register 

    // aRxBuffer[uhRxCounter++] = (USART_ReceiveData(EVAL_COM1) & 0x7F);

    while (aRxByte != 0)

      vTaskDelay(5);

    aRxByte = USART_ReceiveData(EVAL_COM1);

    if (xSemaphoreGiveFromISR(semaRXDAvail, &higherPriorityTask) == pdFALSE)

      errorReg[EBUartRXSemaFail] |= EMUartRXSemaFail;

  }

......

The program works well if the input is ''normal'' characters. However, when the received char is 0x1B (escape). Then it will wandering inside the stm32f4xx_usart.c and no longer getting any RXNE interrupt. What's the correct way to handle the escape sequence?

Thanks,

Sink.
3 REPLIES 3
Posted on September 05, 2013 at 18:53

This looks awesome

while (aRxByte != 0)

      vTaskDelay(5);

In the IRQ Handler do something and leave, don't be spinning in loops, or yielding to other tasks. Pretty much guaranteed to dead-lock.

To process ESC sequences implement a simple state machine, and handle each character as it is received, buffer as required, flag for some deferred processing if required.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tonyyu
Associate II
Posted on September 05, 2013 at 20:50

Yeah,

Thanks, I just found out that my RX task is fast enough to handle the escape sequence and got buffer overrun interrupt. Need to check ORE in the ISR.

Sink

tonyyu
Associate II
Posted on September 05, 2013 at 20:51

typo, 'is not'