I know this topic has already been brought up and I have been going through those posts but I still can't get my UART1 RX interrupt working. What I am trying to do is receive the NMEA string from my GPS module which I can see is being delivered to the UART RX pin after inspection with an oscilloscope.

These characters that I am receiving I want to then display on an LCD display which is a piece of the code that I already have running. What I don't understand is why an interrupt is not being triggered when characters are being sent to the UART1 port? I will attach my main() and ISR routine. Any help would be hugely appreciated.

        InitApp();             //initialise ports 
        intLCD();              //initialise LCD
        putsLCD("Initialising \n \t TCAS");
        U1MODEbits.UARTEN = 1; //enable UART1
        U1MODEbits.PDSEL = 0;   //8 bits, no parity
        U1MODEbits.STSEL = 0; //1 stop bit used
        U1BRG = 1041; //set baud rate to 4800
        U1STAbits.URXISEL = 0; //interrupt flag bit is set when a character is received

        PORTSetPinsDigitalOut(IOPORT_F, BIT_5);                    //data transmitter
        PORTSetPinsDigitalIn(IOPORT_F, BIT_4);                     //data receiver

        IEC0bits.U1RXIE = 1;   //enable interrupt
        U1STAbits.URXISEL = 0; //interrupt after character is received

        gpsINITIALISE();        //initialise GPS to receive data
        int check = 0;
        {                   //wait in here for uart interrupt
            if(check == 0)
                sendMessages();  //send message to gps to recieve 0183 message
                check = 1;

void __ISR(_UART_1_VECTOR, ipl6) _U1RXInterrupt(void)
    putsLCD("interrupt \n \t triggered");
    if(U1STAbits.OERR == 1)
        U1STAbits.OERR = 0;

    if(U1STAbits.URXDA) //check if data is ready to be read
            c = getcUART1();
            if(c == '$') //c == $, hex=0x0024
                count = 0;

            if(count < 6)
                dataTemp[count] = c;
            else if(count > 5 && count < 80)
                else  //error


    //parse GPS
        GPStest();              //function to test GPS
    IFS0bits.U1RXIF = 0; //clear RX interrupt flag
  • \$\begingroup\$ Maybe the UART RX pin is multiplexed and it's used by another peripheral. \$\endgroup\$ – m.Alin Sep 11 '14 at 10:09
  • \$\begingroup\$ Also, the code inside this statement if(check == 0) doesn't seems to get executed. The check variable is always zero (it doesn't seem to get modified anywhere). \$\endgroup\$ – m.Alin Sep 11 '14 at 10:50

You enabled the UART module, but its receiver and transmitter blocks remained unpowered. You need to set:

U1STAbits.URXEN = 1; //enable receiver
U1STAbits.UTXEN = 1; //enable transmitter

Setting GPIO mode by \$\texttt{PORTSetPinsDigital}\$ is unnecessary because PIC32 automatically switches the pin setting whenever a peripheral starts to use it.

| improve this answer | |
  • \$\begingroup\$ That's what drives me nuts about PICs. There's always some other bit you need to set to make things work. \$\endgroup\$ – Rocketmagnet Sep 11 '14 at 21:41
  • \$\begingroup\$ looks like that was the problem, thanks for pointing it out. \$\endgroup\$ – brook Sep 12 '14 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.