PIC32MX795F512H UART1 Multi vectored mode issue....
I am using PIC32MX795F512H (64 pin) device with XC32 (V1.43)compiler for my project, presently I have configured two timers TIMER1 and TIMER3 for different purposes and UART1 module ,and in configuration I have programmed it to run for different speeds, and talking about interrupts I have configured for multi vectored mode as mentioned below
INTCONbits.MVEC = 1; //Interrupt controller configured for Multi-vector mode
__builtin_enable_interrupts(); //Enable Interrupt Exceptions globally Note:
All initializations of UART, TIMERS that I am using are done prior to enabling of global interrupts (as I have read somewhere this information) #PRAGMA part:
#pragma config FSRSSEL = PRIORITY_7 // SRS Select (SRS Priority 7)
#pragma config FUSBIDIO = ON // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = ON // USB VBUS ON Selection (Controlled by USB Module)
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider (2x Divider)
#pragma config FPLLMUL = MUL_20 // PLL Multiplier (20x Multiplier)
#pragma config UPLLIDIV = DIV_12 // USB PLL Input Divider (12x Divider)
#pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1 // System PLL Output Clock Divider (PLL Divide by 1)
#pragma config FNOSC = FRCPLL // Oscillator Selection Bits (FRC Osc w. PLL)
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = OFF // Primary Oscillator Configuration (OFF mode)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_2 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/2) 40Mhz
#pragma config FCKSM = CSDCMD // Clock Switch and Mon Sel (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config FWDTEN = OFF // Watchdog Timer Disable (WDT Disabled (SWDTEN Bit Controls))
#pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled) Coming to initializations and priorities of timers and uart modules:
T1CONbits.TON = 0; //stop timer 1
T1CON = 0X00; // Pre-Scale = 1:1 (T1Clk: 80MHz)
PR1 = 3400; //load period reg with 3400 for 85us
TMR1 = 0; //clear tmr 1
IPC1bits.T1IP = 7; //priority level 7
IFS0bits.T1IF = 0; //clear interrupt flag
IEC0bits.T1IE = 1; //enable interrupt
T1CONbits.TON = 1; //start the timer peripheral
T3CONbits.TON = 0; //stop timer 1
T3CON = 0X00; // Pre-Scale = 1:1 (T1Clk: 80MHz) //
PR3 = 40000; //load period reg 1ms
TMR3 = 0; //clear tmr 1
IPC3bits.T3IP = 7; //priority level 7
IFS0bits.T3IF = 0; //clear interrupt flag
IEC0bits.T3IE = 1; //Enable interrupt
T3CONbits.TON = 1; // start the timer peripheral
//---------------------Cache and Pre fetch initialization---------------------//
BMXCONbits.BMXWSDRM = 0; //Data RAM access from CPU have zero wait states CHECONbits.PFMWS = 2; //PFM Access Time Defined in Terms of SYSLK Wait States
CHECONbits.PREFEN = 1; //Enable predictive pre fetch only for cacheable regions
U1MODE = 0x8000; //Enable UART for 8-bit data
U1STA = 0x5400; //Refer data sheet
IPC6bits.U1IP = 7; //priority level7
IPC6bits.U1IS = 0; //sub priority level0
IEC0bits.U1RXIE = 1; //RX Interrupt enable
IEC0bits.U1TXIE = 1; //TX Interrupt enable
IFS0bits.U1RXIF = 0; //clear RX interrupt flag
IFS0bits.U1TXIF = 0; //clear TX interrupt flag Below shows the ISR’s that im using for TIMER1, TIMER3 and UART1 modules:
void __ISR (_TIMER_1_VECTOR, IPL7SRS) Timer1Handler (void)
//My Application code
IFS0bits.T1IF = 0;
void __ISR (_TIMER_3_VECTOR, IPL7SRS) Timer3Handler (void)
//My Application code
IFS0bits.T3IF = 0;
void __ISR(_UART_1_VECTOR, IPL7SRS) Uart1Handler(void)
led_reg.onoff.R_led = C_ON; //LED to indicate UART TX or RX interrupt
if (IFS0bits.U1RXIF == 1) //generated if RX buffer if full
//My Application code
IFS0bits.U1RXIF = 0; //Clear Receive Interrupt
if (IFS0bits.U1TXIF == 1) // generated if TX buffer is empty
//My Application code
IFS0bits.U1TXIF = 0; //Clear Transmit Interrupt
NOTE: IM using LCD and LEDS and SWITCHES for different purposes and I am using TIMERS for that purpose Problem part:
- 1. As I was able to run all three modules (i.e. TIMER1 (priority 7), TIMER3 (priority 7) and UART1 (did not mention any priority)) under single vectored interrupts I was able to make all the modules work perfectly (suggests the initialization part is correct) now the requirement is to implement multi vectored mode (I am forced to give priorities)and I am having some issues.
- 2. I am able to run both timers perfectly (tried toggling some LED under timer ISR both worked as programmed) so my LCD, LED and Switches (multiplexed) are perfect.
- 3. I am having issue with UART, as mentioned above I am using an LED to check if there is an interrupt or not, but I am unable to see LED toggling inside the UART ISR.
- 4. If I put the RX and TX interrupt monitoring part under the timer3 ISR I am able to communicate my device with UART priority 0 but if I change the priority to any level entire (LDC,LEDs ) thing keep resetting periodically.
- 5. I tried changing priorities for timers (timer1 priority 6 and timer3 priority 7 as such) the timer stops working (LEDs stop working).
- 1. What is the priority I have to set for each module so that everything works fine (I didn’t have any issues in single vectored mode for priorities).
- 2. Do the priorities depend on the speeds of the timers or any modules I am using?
- 3. If the priorities of all three modules are set to level 7 (sub priorities are 0)both timers works fine but not UART (how actually timers works on same priority and what happens with UART to reset module )
- 4. Is the function written for UART ISR has any mistakes so I am unable to get the interrupt inside that function.
- 5. Is there any issue with FSRSSEL = PRIORITY_7 under pragma part (I read in some website saying it matters for priorities, which I didn’t find any difference when I tried to change).
- 6. Do I need much knowledge about priorities and handling, suggest any links…