1
\$\begingroup\$

I'm kinda new to pic32 and have been trying to get the uart to enter the ISR when it receives a byte on the Rx pin. My uart setup works fine both sending and receiving (if I use blocking to read the received byte). But I want to use interrupts to achieve a more 'realtime' feel (since the pic is doing a bunch of other stuff).

This is my code for configuring the uart and Rx interrupt:

INTCONbits.MVEC = 1;

// Peripheral Pin Select    
U1RXRbits.U1RXR = 2;    // Set PA4 to RX
RPB15Rbits.RPB15R = 1;  // Set RB15 to TX

// UART1 Configuration
U1MODE = 0;
U1MODEbits.PDSEL = 0;
U1MODEbits.STSEL = 0;
U1BRG = Baud2BRG(9600);

// Configure UART1 RX Interrupt
IEC1bits.U1RXIE = 0;    // Disable interrupt
IFS1bits.U1RXIF = 0;    // Clear the interrupt flag
IPC8CLR = 0x001f;       // Clear priority vector
IPC8bits.U1IP = 7;      // Set priority
IPC8bits.U1IS = 3;      // Set sub priority
IEC1bits.U1RXIE = 1;    // Enable the interrupt

// Enable UART1
U1STAbits.UTXEN = 1;
U1STAbits.URXEN = 1;
U1MODEbits.ON = 1;

And for handling the interrupt:

extern "C" {
    void __ISR( _UART1_VECTOR, ipl7SOFT) uartRxHandler(void)
    {
        IEC1bits.U1RXIE = 0;    // Disable the interrupt

        Serial1Tx( "works");

        IFS1bits.U1RXIF = 0;   // Clear the interrupt flag
        IEC1bits.U1RXIE = 1;   // Enable the interrupt
    }
}

I just send a simple message back to see if it ever gets into the ISR. I can't understand why the interrupt is never triggered. Thanks for any assistance.

Edit: I'm using MPLAB X with the XC32 compiler and a PICKit3 to program

\$\endgroup\$
  • \$\begingroup\$ What is the full part number of your pic? \$\endgroup\$ – vini_i Oct 20 '15 at 21:01
  • \$\begingroup\$ I'm using the pic32mx220f032b \$\endgroup\$ – Tim Oct 21 '15 at 4:50
  • \$\begingroup\$ Do you have other interrupts confirmed working? (Just checking that you have globally enable interrupts in the co-processor) \$\endgroup\$ – justing Jan 17 '16 at 3:44
  • \$\begingroup\$ How many bytes are you receiving? Is the baud rate of both the same? Check for any error status that may be occurring like I overflow, parity error etc. \$\endgroup\$ – AkshayImmanuelD Mar 27 '16 at 7:23

Your Answer

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

Browse other questions tagged or ask your own question.