1
\$\begingroup\$

I'm trying to setup a UART channel on my PIC32 MCU (PIC32MX470F512). But the code does not reach the ISR at all.

I have verified that the PPS (peripheral pin select) is configured properly and the UART reception under polling mode works perfectly fine. Also, the transmission part is working without any issue from day one. But I need to get UART rx to work with interrupts for my application.

At first I tried using the plib (which didn't work either) but then decided to hand code it eliminate any issues caused by the library. Here is the configuration that I have done.

void UART1Inint(unsigned long int baudRate) {
  ANSELDCLR = 0xFFFF;
  CFGCONbits.IOLOCK = 0;      // PPS Unlock
  RPD11Rbits.RPD11R = 3;        // Assign RPD11 as U1TX
  U1RXRbits.U1RXR = 3;      // Assign RPD10 as U1RX
  CFGCONbits.IOLOCK = 1;      // PPS Lock

  // Baud related stuffs.
  U1MODEbits.BRGH = 1;      // Setup High baud rates.
  unsigned long int baudRateDivider = ((GetSystemClock()/(4*baudRate))-1);
  U1BRG = baudRateDivider;  // set BRG

  // UART Configuration
  U1MODEbits.ON = 1;    // UART1 module is Enabled
  U1STAbits.UTXEN = 1;  // TX is enabled
  U1STAbits.URXEN = 1;  // RX is enabled

  // UART Rx interrupt configuration.
  IFS1bits.U1RXIF = 0;  // Clear the interrupt flag
  IFS1bits.U1TXIF = 0;  // Clear the interrupt flag

  INTCONbits.MVEC = 1;  // Multi vector interrupts.

  IEC1bits.U1RXIE = 1;  // Rx interrupt enable
  IEC1bits.U1EIE = 1;
  IPC7bits.U1IP = 7;    // Rx Interrurpt priority level
  IPC7bits.U1IS = 3;    // Rx Interrurpt sub priority level
}

And Here is how my ISR looks,

void __attribute__((vector(_UART_1_VECTOR), interrupt(IPL7SRS), nomips16)) UART1_ISR(void)
{
  PORTAbits.RA4 = 1;    // LED to indicate the ISR.
  char curChar = U1RXREG;
  U1TXREG=curChar;  // Echo back the same character.
  while(!U1STAbits.TRMT);
  IFS1bits.U1RXIF = 0;  // Clear the interrupt flag!
}

I'm doing two kinds of test in the main loop. One will poll for data in rx and then echo it back to the user. The other will monitor the RILDE flag and turn on an LED to show when the rx pin is actually active. It also toggles a bunch of LEDs for the error flags (least significant 3 bits in U1STA register) in UART1 module.

Both the tests are working fine which indicates that the UART module is setup fine. Just the interrupt portion of it is faulty. So I tested this code on Explorer 16 Development Board, Bluetooth Audio Development Board and the Ethernet Started Kit. I did this to eliminate any hardware related issue as all the three boards are microchip certified hardware.

I don't know what I am missing out please help me fix this issue. Any help would be greatly appreciated.

\$\endgroup\$
  • \$\begingroup\$ Have you checked if the interrupt flag gets set? \$\endgroup\$ – Bruno Ferreira Oct 24 '14 at 11:25
  • \$\begingroup\$ How are you configuring the interrupt system? On the PIC32 it's considerably harder than just setting an "on" flag like the simpler chips. It has different modes (single vector, multi vector, etc), and which mode it's running in is critical to how you write your ISRs and such. \$\endgroup\$ – Majenko Oct 24 '14 at 11:33
  • \$\begingroup\$ @BrunoFerreira, Just tried your idea. The RX interrupt fag is set when I give a character form the terminal. \$\endgroup\$ – Siddharth Oct 24 '14 at 12:23
  • \$\begingroup\$ @Majenko-notGoogle, I have chosen multi vectored interrupts. I guess this line (INTCONbits.MVEC = 1) will take care of that. \$\endgroup\$ – Siddharth Oct 24 '14 at 12:27
  • \$\begingroup\$ @Siddharth Then the problem must be related to the interrupt configuration. Have you checked that the MVEC bit gets set? If not, you could try to replace the code you are using to set the bit with INTEnableSystemMultiVectoredInt(); \$\endgroup\$ – Bruno Ferreira Oct 24 '14 at 12:55
1
\$\begingroup\$

It would be great if you say how you are debugging or checking whether the UART is working correctly or not.

But I would suggest some things that you should look in to.And it will help to find the problem by yourself.

  1. Check whether the RX and TX pins were configured correctly from data sheet.

  2. Trouble shoot your h/w connections: Cross check whether RX and TX were connected properly RX - Should go to TX of target chip TX - Should go to RX of target chip you were communicating.

  3. Is your UART working well?

You should see whether signals are getting transmitted in TX mode.

main()
{
    while(1)
    {
        uart_send('a');  //Some function like this or as you can code.
    }
}
  1. If 1,2 and 3 works try for Reception via RX pin also. You can try serial terminal apps to see whether your UART is working fine. 90% of the time it is connection and baudrate error.
\$\endgroup\$
  • 1
    \$\begingroup\$ Did you read my question? I did mention that my UART (rx and tx) is working properly. That itself rules out all the 4 options you suggested. My issue is only with the interrupt part of it. (I have updated my question with the tests that I have done so far) \$\endgroup\$ – Siddharth Oct 24 '14 at 17:16

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.