2
\$\begingroup\$

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.

main()
{
        InitApp();             //initialise ports 
        intLCD();              //initialise LCD
        clrLCD();
        putsLCD("Initialising \n \t TCAS");
        INTEnableSystemMultiVectoredInt();
        //UART
        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

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

        gpsINITIALISE();        //initialise GPS to receive data
        int check = 0;
        while(1)
        {                   //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();
            while(BusyUART1());
            if(c == '$') //c == $, hex=0x0024
            {
                count = 0;
            }

            if(count < 6)
            {
                dataTemp[count] = c;
                count++;
            }
            else if(count > 5 && count < 80)
            {
                if(dataTemp[4]=='G')
                    GGA[count]=c;
                else  //error

                count++;
            }
        }

    //parse GPS
    parseGPS();
        GPStest();              //function to test GPS
    IFS0bits.U1RXIF = 0; //clear RX interrupt flag
}
\$\endgroup\$
  • \$\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
3
\$\begingroup\$

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 | |
\$\endgroup\$
  • \$\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.