PIC32 XC32 interrupt - Page 1
Forum section: electronics / general

author: firstcolle
author_rank: Regular Contributor
timestamp: November 21, 2018, 09:21:50 am
content: Hi everyone.I'm studying the PIC32MZ ad I have some trouble with the interrupts handler with XC32 compiler.I read a lot (Datasheet, developer help, forums ecc..) and I understand the differences between single vector and multi-vector interrupts.but when I try to experiment with that I can't get something working...someone has some working example for a simple interrupt in both methods?thanks

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: November 21, 2018, 09:39:16 am
content: Code:#include <sys/attribs.h>__ISR_AT_VECTOR (_TIMER_2_VECTOR, IPL4SRS) T2Interrupt(void){IFS0CLR=_IFS0_T2IF_MASK; // clear int}void setupints(void){T2CON=1<<15;TMR2=0;IFS0CLR=_IFS0_T2IF_MASK;IEC0bits.T2IE=1;IPC2bits.T2IP = 4; // int priority/* Assign PIC32MZ shadow register sets to specific CPU IPLs */PRISS = 0x76543210;INTCONSET = _INTCON_MVEC_MASK;__builtin_enable_interrupts();}

author: firstcolle
author_rank: Regular Contributor
timestamp: November 27, 2018, 05:05:14 pm
content: hi,thanks!!now i'm ok with multivectored interrupt but I cant get single vector interrupt working.. is just for study, i know that multivectored is the best way to handle ISRi did this:Code:INTCONbits.MVEC = 0; // single vectorPRISSbits.SS0 = 1; // using shadow registerIFS0bits.INT3IF = 0;IEC0bits.INT3IE = 1;IPC4bits.INT3IP = 2; // priority 2IPC4bits.INT3IS = 0; // sub prioprity 0INTCONbits.INT3EP = 0; // falling edgeIFS0bits.INT1IF = 0;IEC0bits.INT1IE = 1;IPC2bits.INT1IP = 2; // 1IPC2bits.INT1IS = 0; // 0INTCONbits.INT1EP = 0; // falling edgevoid __attribute__((interrupt(ipl2srs))) priority_2(){if (IFS0bits.INT3IF){LED_3 = !LED_3;IFS0bits.INT3IF = 0;}if (IFS0bits.INT1IF){LED_4 = !LED_4;IFS0bits.INT1IF = 0;}}with this setup and ISR the PIC is in continuous reset...

author: cv007
author_rank: Frequent Contributor
timestamp: November 28, 2018, 04:09:56 am
content: Code:void __attribute__((interrupt(ipl2srs))) priority_2(){Without a vector specified, there is no jump code placed in the vector table.one of these may work better-__attribute__((interrupt, vector(0)))__attribute__((interrupt(single), vector(0)))__ISR_SINGLEI don't know the mz, so there may be other things wrong also- like not setting up single-vector mode correctly, using multiple irq priorities in single-vector mode with ss0 shadow set enabled, etc. I would use objdump to look at the isr code generated, and figure out what it does for various interrupt options.With a pic32mm it is safe/easy to use-__attribute__((interrupt, vector(n)))for every interrupt and the isr code will do the right thing but takes a few more instructions to execute and also generates code that may not be used (if it figures out a shadow set is in use, skip extra save/restore code). The mz is probably a little different.

author: firstcolle
author_rank: Regular Contributor
timestamp: November 28, 2018, 07:19:02 am
content: this seems to work__attribute__((interrupt(single), vector(0)))this will be the only ISR or can I create multiple ISRs with different vector (for different priority)? I tryied, the compiler gives me no error or warning but only the first ISR works..

author: Jan Audio
author_rank: Frequent Contributor
timestamp: November 28, 2018, 03:15:58 pm
content: You can generate the correct code with MCC.Cheap answer, someone gave it to me.edit : meanwhile i also would like to know exactly how it works.

author: firstcolle
author_rank: Regular Contributor
timestamp: November 28, 2018, 03:19:45 pm
content: PIC32MZ2048EFH100 is not supported by MCC.. apart from that.. I don't like MCC/Harmony. I like to study/understand how the pic works.

author: Jan Audio
author_rank: Frequent Contributor
timestamp: November 28, 2018, 03:55:23 pm
content: Oh sorry i did not know,maybe you can generate with the closest chip available ?, or is this whole family not avaiable ?I also dont like MCC, i just generate something and copy the lines i need, i also try other sources, only theres not much.Maybe people will generate it for you in MCC ?, how friendly.

author: firstcolle
author_rank: Regular Contributor
timestamp: November 28, 2018, 03:56:31 pm
content: i think the whole family is unsupported.. l'll try that tonight!!thanks