Hot!PIC32 UART OverRun Error(OERR) Solution required ?

Author
nick703
Senior Member
  • Total Posts : 135
  • Reward points : 0
  • Joined: 2012/06/24 07:11:37
  • Location: 0
  • Status: offline
2017/08/12 01:50:42 (permalink)
0

PIC32 UART OverRun Error(OERR) Solution required ?

Hello Friends,
 
   I have a PIC32MX795F512L configure with UART via comunication using FTDI to PC Application.
In My configuration I have a set Buad Rate 1000000bps both hardware and software. Below is My code
#define SYS_FREQ (80000000L)
#define DESIRED_BAUDRATE (1000000) //The desired BaudRate

void TimerandUartInit(void)
{
 int pbClk;

    pbClk = SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

 OpenUART2(UART_EN |UART_NO_PAR_8BIT | UART_2STOPBITS , // Module is ON
    UART_RX_ENABLE | UART_TX_ENABLE | UART_RX_OVERRUN_CLEAR, // Enable TX & RX
    pbClk/16/DESIRED_BAUDRATE-1); // 1000000 bps, 8-N-1
    UARTSetFifoMode(UART3A, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    ConfigIntUART2(UART_RX_INT_EN | UART_TX_INT_DIS | UART_ERR_INT_EN | UART_INT_PR1 );
}


CHAR dummy;
void __ISR(_UART_2_VECTOR, ipl1) IntUart2Handler(void)
{
 if(IFS1bits.U3ARXIF)
 {
        if(U3ASTAbits.OERR != 0)
        {
         SerialGetDataBuffer();
            U3ASTAbits.OERR = 0;
            IEC1bits.U3ARXIE = 0;
            IEC1bits.U3ARXIE = 1;
        }
        else
        {
            if ((U3ASTAbits.FERR != 0) || (U3ASTAbits.PERR != 0))
            {
                dummy = U3ARXREG;
                U3ASTAbits.FERR = 0;
                U3ASTAbits.PERR = 0;
            }
            else
            {
                SerialGetDataBuffer();
            }
        }
        //while (U3ASTAbits.URXDA != 0);
        IFS1bits.U3ARXIF = 0;
 }
 if(IFS1bits.U3ATXIF)
 {
  IFS1bits.U3ATXIF = 0;
 }
 if(IFS1bits.U3AEIF)
 {
  IFS1bits.U3AEIF = 0;
 }
} // Uart Handler

 
 
in above code SerialGetDataBuffer()  received particular command and processing in main Loop.
in above configuration i have completely send and receive command .
 
But actual Problem is Suppose i have send through PC command like {7Q50000} ,{7P50000}, {7Z50000},{7E50000}, {3UM+},{3XM+},{3ZM+} ...  And also receive same command but whenever UART OERR error set that time i have miss the one of the above packet   {7Q50000} ,{7P50000}, {7Z50000},{7E50000}, {3UM+},{3XM+},{3ZM+}  THIS highlighted command is missing. when Uart Oerr Detect that time only .
but when is UART OERR not detect that time i have received completely all command.
 
So is that any solution to overcome UART OERR set that time also i have to read my whole buffer?
#1

17 Replies Related Threads

    maxruben
    Super Member
    • Total Posts : 3062
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 02:23:10 (permalink)
    0
    Can you show the code for SerialGetDataBuffer()?
     
    /Ruben
    #2
    nick703
    Senior Member
    • Total Posts : 135
    • Reward points : 0
    • Joined: 2012/06/24 07:11:37
    • Location: 0
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 02:32:54 (permalink)
    0
    ok below is code
     
    CHAR ReceiveData[20], ProcessCommand[20];

    void SerialGetDataBuffer(void)
    {
        char Command, Count = 0;
        mLED_1_On(); 
        Command = U3ARXREG;
        if(Command == '{')
        {
            for(Count = 0; Count < 20; Count++)
            {
                ReceiveData[Count] = '\0';
            }
            i = 0;
            bCommandStart = 1;
        }
        else if(Command == '}')
     { 
            if(bCommandStart)
      {
       strcpy(ProcessCommand, ReceiveData);
       strcpy(ReceiveData, "");
       bCommandStart = 0;
       i = 0;
      }
      else
      {
       strcpy(ReceiveData, "");
       bCommandStart = 0;
       i = 0;
      }
     }
     else if( i >= 20)
     {
      for(Count = 0; Count < 20; Count++)ReceiveData[Count] = '\0';
      bCommandStart = 0;
      i = 0;
     }
     else
     {
      ReceiveData[i++] = Command;
     }
    }

    void TransmitUart2(char* pstring)
    {
     while(*pstring != '\0')
     { 
      while(U3ASTAbits.UTXBF){}
            U3ATXREG = *pstring;
      pstring ++;
        }
    } // End of Transmit

    int main(void)
    {
    TimerandUartInit();
    INTEnableSystemMultiVectoredInt();
    while(1)
       {
           if(strlen(ProcessCommand) > 0)
        {
                   char Null = 0;
                
                    if(!strncmp(ProcessCommand, "3QFG", sizeof("3QFG")))
                   {
                   }
               }
              while(Null < 20)
       {
        ReceiveData[Null] = '\0';
        ProcessCommand[Null++] = '\0'; 
       }
       }
     return 0;
    }

     
     Above is my receive and transmit code and main loop to compare match string and processing data.
    #3
    andersm
    Super Member
    • Total Posts : 2154
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 02:43:03 (permalink)
    3 (1)
    An obvious first step would be to raise the interrupt priority to 7, and make sure it's using shadow registers to reduce the interrupt overhead. Also make sure you're not disabling interrupts anywhere. Make sure to drain the FIFO completely inside the ISR. Use DMA for data transfer (use the pattern match feature, or alter the protocol to use fixed-length packets). Evaluate if you really need that high transfer speeds or if you can lower it to something less taxing.
    #4
    nick703
    Senior Member
    • Total Posts : 135
    • Reward points : 0
    • Joined: 2012/06/24 07:11:37
    • Location: 0
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 02:54:40 (permalink)
    0
     
     let me know what is the wrong with my above code ? is that i have doing some  wrong code in receive?
     
    Use DMA for data transfer (use the pattern match feature, or alter the protocol to use fixed-length packets).   i didn't explain please give me some reference regarding this.  
    #5
    Antipodean
    Super Member
    • Total Posts : 1543
    • Reward points : 0
    • Joined: 2008/12/09 10:19:08
    • Location: Didcot, United Kingdom
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 03:23:49 (permalink)
    3 (1)
    nick703
    Hello Friends,
     
       I have a PIC32MX795F512L configure with UART via comunication using FTDI to PC Application.
    In My configuration I have a set Buad Rate 1000000bps both hardware and software.



    Why are you using a non-standard baud rate? I suspect the PC is not setting the FTDI to that baud rate, but picking the nearest standard one.
     
    You also do not mention if the FTDI device has an RS232 interface (in which case you need something like a MAX3232 between your PIC and the FTDI) or if the FTDI has a TTL interface. In either case have you checked your PIC is set to the correct polarity output and input? Some PICs can invert the sense of serial data by setting a bit in the UART setup registers. I haven't looked through your code to see if you have checked this, that is your job.
     

    Do not use my alias in your message body when replying, your message will disappear ...

    Alan
    #6
    nick703
    Senior Member
    • Total Posts : 135
    • Reward points : 0
    • Joined: 2012/06/24 07:11:37
    • Location: 0
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 03:52:35 (permalink)
    0
    I am using FTDI232RL which ic supported fully rs232 protocol.
     
    bu problem is overflow error OERR . when this bit is set and clear that time i missing the packet.
    #7
    RISC
    Super Member
    • Total Posts : 4229
    • Reward points : 0
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 04:08:12 (permalink)
    0
    Hi,
    Please reply to the questions in post #6
    Regards
    #8
    CinziaG
    rome burns :D
    • Total Posts : 2699
    • Reward points : 0
    • Joined: 2016/12/07 14:20:36
    • Location: Wien
    • Status: online
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 04:08:28 (permalink)
    0
    Yep, you should never do all of that processing (strcpy etc) inside an ISR.
    #9
    nick703
    Senior Member
    • Total Posts : 135
    • Reward points : 0
    • Joined: 2012/06/24 07:11:37
    • Location: 0
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 04:18:29 (permalink)
    3 (1)
    Sorry RISC ,I didn't Understand ?
    Is that Baud rate Issue? 
    But i use same Baud rate in software and also Hardware so what's Wrong ?
     
    is that strcpy cause this problem? ok fine then what is alternative?
     
     
    #10
    maxruben
    Super Member
    • Total Posts : 3062
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 04:59:40 (permalink)
    4.5 (2)
    Baudrate should not be the problem. At least not for the overrun error problem. It may cause framing and parity error though.
     
    Only call library functions that are reentrant safe from an interrupt. Not sure if strcpy and the likes are.
     
    I can't see in your code where you actually process the command. This should not be in the same interrupt context as the UART interrupt.
     
    You have a function TransmitUart2(). This is a blocking function that can take quite some time (depending on how long string you send). This can not be called from the interrupt context.
     
    You should, as Anders M says, read the entire fifo for every interrupt.
     
    /Ruben
    #11
    rpg7
    Super Member
    • Total Posts : 1315
    • Reward points : 0
    • Joined: 2003/11/07 12:47:35
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 05:12:23 (permalink)
    5 (2)
    The interrupt routine should ONLY copy the received data to a circular buffer larger enough to hold the expected data. For many applications I use a 250 byte buffer.
     
    In the main loop you check to see if the input pointer has become different to the output pointer and if so read the char indexed by the output pointer. This char can then be added to a linear buffer for inspection with utilities such a strcmp.
    #12
    CinziaG
    rome burns :D
    • Total Posts : 2699
    • Reward points : 0
    • Joined: 2016/12/07 14:20:36
    • Location: Wien
    • Status: online
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 05:28:56 (permalink)
    4 (1)
    Something like Maxruben and Rpg7 said Smile
    It's not quite "strcpy" the issue, rather the time spent in an ISR; also the reentrant thing could be an issue, anyway. Just grab and store characters in the ISR, and check/compare/process the "packet" inside your main loop.
    #13
    nick703
    Senior Member
    • Total Posts : 135
    • Reward points : 0
    • Joined: 2012/06/24 07:11:37
    • Location: 0
    • Status: offline
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/12 22:54:02 (permalink)
    0
    Please Give me Example or some coding help.
     
    i cant understand completely , i have receive code between  start this bracket  { and  end with this bracket }.
     
    i can't Find how to overcome with OERR i read the datasheet and say only "
    The data in the receive FIFO should be read prior to clearing the OERR bit. The
    FIFO is reset when OERR is cleared, which causes all data in the buffer to be lost.
    "
     
    And same thing above i do but when clear the error i have lost my buffer data. 
     
     
     
    #14
    andersm
    Super Member
    • Total Posts : 2154
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: PIC32 UART OverRun Error(OERR) Solution required ? 2017/08/13 00:50:55 (permalink)
    4 (2)
    Your ISR is too slow. An OERR happens when the FIFO overflows, so data loss is inevitable. The bit from the datasheet you quoted above explicitly says that the FIFO is cleared when the OERR bit is cleared.
     
    You have three options:
    1. Make the ISR faster. This means moving all data processing out of the ISR, it should only move the received characters from the FIFO into a buffer, and check for the end character. Also take advantage of shadow registers, and turn on compiler optimizations.
    2. Use a slower bit rate. You still need to most of the junk out of the ISR, since some of it is not safe to do inside an ISR.
    3. Don't use interrupts at all. Either use polling, or DMA.
    #15
    Jump to:
    © 2017 APG vNext Commercial Version 4.5