• AVR Freaks

UART RX Interrupt problem

Author
hichamrol
Starting Member
  • Total Posts : 50
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: offline
2019/09/05 06:30:54 (permalink)
0

UART RX Interrupt problem

Hi everyone  i am working with pic24fj1024GB610 to interrupt my program when a character is recieved , 
the problem is the interrupt flag is set just for the first 4 character recieved and then its not worked anymore, 
here the configuration i set : 
 
U1MODE = 0x8008 ;
U1STA = 0x00;
U1BRG = 0x08;
U1ADMD = 0x00;
U1MODEbits.UARTEN = 1; // enabling UART ON bit
U1STAbits.UTXEN = 1;
IEC0bits.U1RXIE = 1;
IPC2bits.U1RXIP = 1;

 
and here is the ISR function 
 
void __attribute__ ((interrupt, no_auto_psv)) _U1RXInterrupt(void) 
{

LED_D7_LAT=0;
LED_D6_LAT=1; //


IFS0bits.U1RXIF = 0;


}

 
 
int main(void)

{



while(1)
{

LED_D7_LAT=1;
LED_D6_LAT=0;



}

retrun 1;

}

#1

4 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23596
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: UART RX Interrupt problem 2019/09/05 07:12:09 (permalink)
    0
    You are overflowing the UART's receive buffer because your interrupt service routine never reads the received character.
    You must read it and store it into a FIFO buffer in RAM for your non-interrupt code to read.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    hichamrol
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2019/07/10 07:22:53
    • Location: 0
    • Status: offline
    Re: UART RX Interrupt problem 2019/09/05 07:40:13 (permalink)
    0
    Thank you ric, it worked , so when  Receive buffer has overflowed , i clear the statut bit


    if(U1STAbits.OERR==1)
    {
    U1STAbits.OERR=0;
    }
    #3
    pcbbc
    Super Member
    • Total Posts : 1254
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: UART RX Interrupt problem 2019/09/05 08:02:32 (permalink)
    0
    hichamrol
    Thank you ric, it worked , so when  Receive buffer has overflowed , i clear the status bit


    if(U1STAbits.OERR==1)
    {
    U1STAbits.OERR=0;
    }

    Well, it might work - but it's hardly ideal.
     
    Your problem is you can't clear U1RXIF manually like you were trying in your first example.  The correct way to handle a receive interrupt is to READ the received data from U1RXREG.  That will get you the byte received and clear U1RXIF (as long as there are no more bytes waiting in the receive buffer).
     
    If OERR gets set it indicates you have a problem.  Basically you are not servicing interrupts fast enough.
    #4
    scrungy
    Senior Member
    • Total Posts : 134
    • Reward points : 0
    • Joined: 2016/02/02 09:56:54
    • Location: 0
    • Status: offline
    Re: UART RX Interrupt problem 2019/09/05 10:30:08 (permalink)
    0
    I had the exact same problem.  It turns out that the configurator sets a specific bit, that toggles the enhanced uart mode on.
    In that mode, the interrupt will be set only when the 4 character fifo is full.  Which is why you can get 4 characters, then and interrupt, and no more interrupts until you get 4 more characters. If your message is 6 characters long, you are hose.  Disable enhanced mode, and you will get the behavior you want.  It took me 4 days of hunting to find that one.
    URXISEL  set it ti 0x00  and it will interrupt on every character.  You probably have it set to 0x03
    which will interrupt every 4 characters.
     
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5