Wednesday, 30 March 2016

pic - PIC32 does not get UART RX interrupts in xc32 Compiler


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.




No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...