AnsweredAssumed Answered

S32K144 UART receive bytes missing issue

Question asked by Xiaoyu Wang on Aug 5, 2018
Latest reply on Aug 10, 2018 by Xiaoyu Wang

I am using S32K144 UART peripheral. RXD interrupt and TXD interrupt vector are the same one, so in interrupt handler, we have to check whether due to Rx or Tx that the ISR function is called.

My question 1 is : If ISR is entered due to Tx, at the same time, a Rx byte is shift to data register finished. whether the received byte will be affected?

 

My ISR function just like below:

void UARTSrv_isr(void)
{
      uint8_t lub_temp;

      /* For reception interrupt. */
      if(LPUART1->CTRL & 0X200000)
      {
            if(LPUART1->STAT & 0X200000)
            {
                  lub_temp = (uint8_t)LPUART1->DATA;
                  testTotalReceived += 1;
                  UARTSrv_Rx_isr(lub_temp);
             }
        }

         /* For transmission interrupt. */

         if(LPUART1->CTRL & 0X800000)
         {
               if(LPUART1->STAT & 0X800000)
               {
                     if(lpuart1_State.txSize > 0)
                     {
                           LPUART1->DATA = *lpuart1_State.txBuff;
                           ++lpuart1_State.txBuff;
                             --lpuart1_State.txSize;
                      }
                      else
                      {
                          /* Disable transmission complete interrupt */
                           LPUART_SetIntMode(LPUART1, LPUART_INT_TX_DATA_REG_EMPTY, false);

                           /* Update the information of the module driver state */
                           lpuart1_State.isTxBusy = false;
                           lpuart1_State.transmitStatus = STATUS_SUCCESS;
                       }
                }
          }

         /* For overruninterrupt. */

         if (LPUART1->STAT & 0X80000)
         {
               lpuart1_State.receiveStatus = STATUS_UART_RX_OVERRUN;
               /* Clear the flag, OR the rxDataRegFull will not be set any more */
               LPUART1->STAT |= 0X80000;
         }

}

 

User defined function "UARTSrv_Rx_isr" definition as below:

PRIVATE_FCT void UARTSrv_Rx_isr(uint8_t ch)
{
      pUART_rx_data_t pRx = &rs_rxData;

      if(FALSE == pRx->bufFull)
      {
            pRx->buf[pRx->inIndex] = ch;
            pRx->bufEmpty = FALSE;
            pRx->recBytes += 1u;
            pRx->inIndex += 1u;
            if(UART_RX_DATA_BUF_LEN <= pRx->inIndex)
            {
                  pRx->inIndex = 0u;
            }
            if(pRx->inIndex == pRx->outIndex)
            {
                  pRx->bufFull = TRUE;
            }
        }
}

But when I check my received data, I found that received bytes lost frequently. 

 

My question 2 is: whether my ISR has problem? or my issue is due to other possible reasons?

 

Thank you~~

Additionally: I check the UART receive overrun interrupt, it was entered frequently. How to avoid enter the overrun interrupt or how to process it?

Outcomes