I am using PIC18F46K80, at a baud rate of 115200, a Stop Bit of 1 and no parity. I am sending data from a C# application(Baud Rate 115200, Stop Bit-1 and No Parity) to the PIC. After send some bytes of data, I get an over-run error in the PIC. I have inserted delays before receiving the data in the PIC.
T_UINT8 UARTReceive(T_UINT8 *t_ret)
{
*t_ret = 0;
T_UINT8 temp;
while(!PIR1bits.RC1IF)
{
/* Wait till the data is received */
if((RCSTA1bits.FERR) || (RCSTA1bits.OERR) )
{
temp=RCREG1;
temp=RCREG1;
temp=RCREG1;
temp=RCREG1;
temp=RCREG1;
// EUSART1 error - restart
RCSTA1bits.CREN = 0;
asm("NOP");
RCSTA1bits.CREN = 1;
*t_ret = 1;
return 0;
}
}
if(RCSTA1bits.OERR==1)
{
k=30;
}
/* Return the received data */
Delay100TCYX(0);
asm("NOP");
asm("NOP");
return RCREG1;
}
Even after inserting large delay, I am getting an over-run error, on maintaining the same baud rate in C# application . How do I avoid over-run errors while receiving data in my PIC?