It is currently 23 Feb 2019 13:46

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: 16 Jan 2019 15:04 
Offline

Joined: 06 Apr 2016 07:44
Posts: 21
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:

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


Top
 Profile  
 
PostPosted: 17 Jan 2019 11:17 
Offline
mikroElektronika team
User avatar

Joined: 18 Dec 2018 10:30
Posts: 129
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.

PPS_Mapping(_RPE9, _INPUT, _INT2);


Kind regards,

_________________
Stefan Filipović


Top
 Profile  
 
PostPosted: 17 Jan 2019 14:08 
Offline

Joined: 06 Apr 2016 07:44
Posts: 21
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 :

/*
 * 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);
  }

}


Top
 Profile  
 
PostPosted: 17 Jan 2019 15:17 
Offline
mikroElektronika team
User avatar

Joined: 18 Dec 2018 10:30
Posts: 129
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ć


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: