external interrupts on PIC32MZ

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
gg-rpg
Posts: 28
Joined: 06 Apr 2016 07:44

external interrupts on PIC32MZ

#1 Post by gg-rpg » 16 Jan 2019 15:04

Greetings to all,

I try to convert one of my PIC32-projects from PIC32MX795 to PIC32MZ2048EFH144.
My goal is, to keep the pin-configuration for the EasyPicV7-MCU-Card.

- LCD -> OK
- SPI for ADC -> OK
- SPI for PortExpander -> OK
- external interrupt on Port E.9 -> fail

After several days of research and try&error ... I count on your experts-knowledge to solve my last problem with external interrupts.

Here my "old" ... working ... MX-code for interrupt on Pin E9:

Code: Select all

void clear_all_ints()
{
  INT0IF_bit = 0;                    // Reset INT0 flag
  INT1IF_bit = 0;                    // Reset INT1 flag
  INT2IF_bit = 0;                    // Reset INT2 flag
  INT3IF_bit = 0;                    // Reset INT3 flag
  INT4IF_bit = 0;                    // Reset INT4 flag
}

void init_int()
{

  MVEC_bit = 1;

  INT2IP0_bit = 0;                   // Set INT2 interrupt
  INT2IP1_bit = 0;                   // priority
  INT2IP2_bit = 1;                   // to 4
  INT2EP_bit  = 0;                   // falling edge
  INT2IE_bit  = 1;                   // Set interrupt on INT2 (RE9) to be enabled
}

void int2_interrupt() iv IVT_EXTERNAL_2 ilevel 4 ics ICS_AUTO          // E9
{
  ... things to do ...
   clear_all_ints();
}
Thanks in advance ...
Gunther

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: external interrupts on PIC32MZ

#2 Post by stefan.filipovic » 17 Jan 2019 11:17

Hi Gunther,

To use external interrupt 2 with the PIC32MZ2048EFH144 you should use PPS for mapping to the pin which can be used for that.
As described in the datasheet you can use RE9 pin with INT2.
Please see pages 21 and 260 of the datasheet.

So, you could use our Peripheral_Pin_Select library to map the INT2 to the RE9 as shown below.

Code: Select all

PPS_Mapping(_RPE9, _INPUT, _INT2);
Kind regards,
Stefan Filipović

gg-rpg
Posts: 28
Joined: 06 Apr 2016 07:44

Re: external interrupts on PIC32MZ

#3 Post by gg-rpg » 17 Jan 2019 14:08

Hello Stefan,

for the 32MZ ... I have a lot to learn ... although I have over 10 years experience with PIC ... :wink:
Many thanks to your help ... here the result ... a working test-code :

Code: Select all

/*
 * Project name:
     test_int
 * Description:
     interrupt test
 * Test configuration:
     MCU:             P32MZ2048EFH144
                      http://www.microchip.com/wwwproducts/en/PIC32MZ2048ECH124
     dev.board:       easypic fusion v7 -
                      http://www.mikroe.com/easypic-fusion/
     Oscillator:      XT-PLL, 200.0000MHz
     Ext. Modules:    None.
     SW:              mikroC PRO for PIC32
                      http://www.mikroe.com/mikroc/pic32/
 * NOTES:

*/

//*******************************************
// Init-I/O
//*******************************************
void init_MCU()
{
  JTAGEN_bit = 0;

  ANSELA = 0;
  ANSELB = 0;
  ANSELC = 0;
  ANSELD = 0;
  ANSELE = 0;
  ANSELF = 0;
  ANSELG = 0;

  TRISA = 0;
  TRISB = 0;
  TRISC = 0;
  TRISD = 0b0000000000000000;
  TRISE = 0b0000001000000000;
  TRISF = 0b0000000000000000;
  TRISG = 0b0000000000000000;

  LATA = 0;
  LATB = 0;
  LATC = 0;
  LATD = 0b0000000000000000;
  LATE = 0b0000000100000000;
  LATF = 0b0000000000000000;
  LATG = 0b0000000000000000;

   Unlock_IOLOCK();

     PPS_Mapping( _RPE9, _INPUT, _INT2 );

   Lock_IOLOCK();

}

//*******************************************
// Interrupts
//*******************************************
void INT2_Interrupt() iv IVT_EXTERNAL_2 ilevel 4 ics ICS_AUTO
{
   IFS0.B13 = 0;                        // INT2IF_bit
   LATB.B1=~PORTB.B1;
}

//*******************************************
// MAIN
//*******************************************
void main()
{
  // setup hardware
  init_MCU();

  // Initializing Interrupts
  Disableinterrupts();      // Disable all interrupts

    MVEC_bit = 1;           // multi-vectored-interrupt

    INT2IP0_bit = 0;        // Set INT2 interrupt
    INT2IP1_bit = 0;        // priority
    INT2IP2_bit = 1;        // to 4
    INT2EP_bit  = 0;        // falling edge
    INT2IE_bit  = 1;        // Set interrupt on INT2 (RE9) to be enabled

  EnableInterrupts();       // Enable all interrupts

  // endless loop
  while(1)
  {
    LATB.B0=~PORTB.B0;
    Delay_ms(100);
  }

}

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: external interrupts on PIC32MZ

#4 Post by stefan.filipovic » 17 Jan 2019 15:17

Hi Gunther,

You're welcome.

By the way, you do not need to use Unlock and Lock I/O if you use PPS_Mapping, only if you use PPS_Maping_NoLock.

This is useful when you want to map several pins, you will be able to do it with just one Unlock/Lock.

Kind regards,
Stefan Filipović

Post Reply

Return to “mikroC PRO for PIC32 General”