UART_EVENT_ERR_OVERFLOW in UART Comminication

Hi Everyone;

I am trying to communicate with Uart. But I am encountering such an error. What could be the reason for this?

I see the same error when I activate FIFO Support. The difference between activating and not activating FIFO Support is that when FIFO Support is active, the error occurs after a while. What does FIFO Support do?

Thank you in advance.

Regards.
guurii

Parents Reply Children
  • Can you share your code where you call R_SCI_UART_Read ? It could be possible that you do not wait until the receive operation is completed before you receive new data.

  • Hi,

    The code I want to write is like below.
    What should I do to wait for the receive operation is complete before receive new data?

    #define UART1_RECEIVEBUFFERSIZE 100
    static unsigned char uart1_Receivechar = 100;
    static unsigned char uart1_Transmitchar = 100;
    static unsigned char Uart1ReceiveBuffer[UART1_RECEIVEBUFFERSIZE];
    static unsigned char Uart1ReceiveCounter = 0U;
    unsigned char uartByte;
    void user_uart_callback(uart_callback_args_t *p_args)
    {
        /* Handle the UART event */
        switch (p_args->event)
        {
        /* Received a character */
        case UART_EVENT_RX_CHAR:
        {
            break;
        }
        /* Receive complete */
        case UART_EVENT_RX_COMPLETE:
        {
            ata_Uart1_ReceiveInterrupt();
            break;
        }
        /* Transmit complete */
        case UART_EVENT_TX_COMPLETE:
        {
            ata_Uart1_TransmitInterruptEnd();
            break;
        }
        default:
        {
        }
        }
        
    }
    
    static void Uart1ByteReceived(unsigned char uartByte)
    {
        if (Uart1ReceiveCounter < UART1_RECEIVEBUFFERSIZE)
        {
            Uart1ReceiveBuffer[Uart1ReceiveCounter++] = uartByte;
        }
        else
        {
            Uart1ReceiveCounter = 0U;
            trk_PushMessage1msNullUserData(&CheckUartReceiveBufferThread);
        }
    }
    
    void Uart1ReceiveInterrupt(unsigned char Received_Byte)
    {
        Uart1ByteReceived(Received_Byte);
    }
    
    unsigned long CheckUartReceiveBufferThread(void *user_data)
    {
        unsigned char ReceiveCounter;
        unsigned char ReceiveCounterControl = 0U;
        if (Uart1ReceiveCounter != 0U)
        {
            ReceiveCounterControl = Uart1ReceiveCounter;
            for (ReceiveCounter = 0U; ReceiveCounter < ReceiveCounterControl; ReceiveCounter++)
            {
                ata_commcallback(Uart1ReceiveBuffer[ReceiveCounter]);
            }
            if (ReceiveCounterControl == Uart1ReceiveCounter)
            {
                Uart1ReceiveCounter = 0U;
            }
            else
            {
                for (ReceiveCounter = 0U; ReceiveCounter < (Uart1ReceiveCounter - ReceiveCounterControl); ReceiveCounter++)
                {
                    Uart1ReceiveBuffer[ReceiveCounter] = Uart1ReceiveBuffer[ReceiveCounterControl + ReceiveCounter];
                }
                if (Uart1ReceiveCounter >= ReceiveCounterControl)
                {
                    Uart1ReceiveCounter = (Uart1ReceiveCounter - ReceiveCounterControl);
                }
            }
        }
        return (unsigned long)msg_ProcessAfter1ms * 10U;
    }
    
    void ata_Uart1_ReceiveInterrupt(void)
    {
        Uart1ReceiveInterrupt(uart1_Receivechar);
        R_SCI_UART_Read(&g_uart0_ctrl, (uint8_t *)&uart1_Receivechar, 1);
    }

    Thanks.

  • You can add a delay at RX_COMPLETE to wait your process done.

  • I think you're right. I put a breakpoint in r_sci_uart_c where r_sci_uart_call_callback is and when I debugged I saw that the buffer filled without any problems.

    I will follow your advice.

    Thanks for be interested.

  • I added delay but still the problem was not solved. Anyone have an idea?

  • Hi guurii.  There are 2 interrupt events when it comes to reads. 

    UART_EVENT_RX_CHAR // Fires after "every" character... this is the most common

    UART_EVENT_RX_COMPLETE // Fires ONLY when the amount of data specified in the read is received

    Most applications using UART are connected to some sort of HMI, like a terminal, and receive 1 character at a time and use the first interrupt UART_EVENT_RX_CHAR to "accumulate" the result.  If it is a machine talking to a machine and you "know" that x amount of data is to be received, like a packet, then you would use the RX_COMPLETE interrupt.  HOWEVER, your code will have to do data-alignment on the packet and handle dropped characters and so on, so I would expect error recovery and alignment code (like looking for a SOP character or something.

    I suspect, your application is expecting one character at a time, in which case you want to use the UART_EVENT_RX_CHAR interrupt.  You can still set the buffer length in the READ call to something other than 1.

    Your error likely stems from the fact when you do your follow-on READ you are specifying a length of 1.  You should always specify a length of whatever the buffer length is...something greater than 1, if you intend to do a "packet" type of interface.

  • Hi Dale,

    Thank you for your attention to this issue.

    My application receive one character at a time.

    Even when I specify a length greater than 1, I continue to get the same error.

    If I disable FIFO Support, I see an overflow error after receiving 1 character.
    If I enable FIFO Support, I can receive 16 characters, then I get the overflow error again.

  • at the same time, If I use 2 instead of 1 in Read, I get an overflow error when the buffer fills up to 8 instead of 16.

  • The FIFO has 16 stages which means it can store up to 16 bytes and their related status information. So when the FIFO is full and a new byte arrives, you will get an overflow error.

  • Thanks for your interest.

    I know that FIFO stores 16 bytes, but how can I empty it after the FIFO is full?

    I still have data to receive and I can't.