Simple external interrupt program (SOLVED)

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
pepper
Posts: 6
Joined: 06 May 2018 17:35

Simple external interrupt program (SOLVED)

#1 Post by pepper » 06 May 2018 17:46

I am new to mikroC and have encountered some problems. I want to enable three external interrupts from three push buttons but i am pretty lost. I am using a pic32mz chip.
I tried this code for one push button which after some playing around to enable an interrupt from F8 but to no avail.

Code: Select all

int flag=0;
void main(){
ANSELA=0;
ANSELF=0;
TRISA=0;
LATA=0xFF;
TRISF8_bit=1;         //button input

  Unlock_IOLOCK();
  PPS_Mapping(58, _INPUT, _INT1);
//RPINR0bits.INT1R = 58;
  Lock_IOLOCK();
  IFS0bits.INT1IF=0;     //clear interrupt flag
  INTCONbits.INT1EP=0;   //interrupt edge
  IPC2bits.INT1IP=1;     //interrupt priority
  IEC0bits.INT1IE=1;     //enable external interrupt
   EnableInterrupts();
               while(1){
                if (flag==1){
                flag=0;
                LATA=~PORTA;
                }
               }
}

 void EXT_INT1() iv IVT_EXTERNAL_1 ics ICS_AUTO
{
   flag=1;
   IFS0.INT1IF =0;
}

What am i doing wrong?

thanks
Last edited by pepper on 02 Jun 2018 10:32, edited 2 times in total.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Simple external interrupt program

#2 Post by filip » 17 May 2018 16:16

Hi,

First of all, are you sure that your button is working correctly ?
Did you try debugging your code without the interrupt, just by polling the PORT register ?

Regards,
Filip.

pepper
Posts: 6
Joined: 06 May 2018 17:35

Re: Simple external interrupt program

#3 Post by pepper » 22 May 2018 18:53

I tested the button and it works with the button library but not with the above interrupt code.

marcelocrr
Posts: 24
Joined: 15 Oct 2012 16:11

Re: Simple external interrupt program

#4 Post by marcelocrr » 23 May 2018 15:17

Pepper,

Try PPS_MAPPING(_RPF8, _INPUT, _INT1) instead of PPS_MAPPING(58, _INPUT, _INT1)

Regards,
Marcelo Rilko.

pepper
Posts: 6
Joined: 06 May 2018 17:35

Re: Simple external interrupt program

#5 Post by pepper » 24 May 2018 14:22

Unfortunately, i have already tried that. I changed the code a bit but i had no success.

Code: Select all

  Unlock_IOLOCK();
  PPS_Mapping(_RPF8, _INPUT, _INT1);
//RPINR0bits.INT1R = 58;
  Lock_IOLOCK();

  IFS0.INT1IF=0;     //clear interrupt flag
  INTCON.INT1EP=0;   //interrupt edge
  //IPC2.INT1IP=1;     //interrupt priority
  IEC0.INT1IE=1;     //enable external interrupt
Also when i write the line

Code: Select all

IPC2.INT1IP=1;     //interrupt priority
it fails to compile. Any ideas?
I'm using a pic32mz.

marcelocrr
Posts: 24
Joined: 15 Oct 2012 16:11

Re: Simple external interrupt program

#6 Post by marcelocrr » 24 May 2018 18:20

Pepper,

What's the P/N of the MCU?

Marcelo Rilko

pepper
Posts: 6
Joined: 06 May 2018 17:35

Re: Simple external interrupt program

#7 Post by pepper » 25 May 2018 14:30

It's pic32mz2048efh100

JairHdez
Posts: 16
Joined: 24 Feb 2017 19:25

Re: Simple external interrupt program

#8 Post by JairHdez » 25 May 2018 15:07

You can't use the F8 pin with the external interrupt 1. In the datasheet (http://ww1.microchip.com/downloads/en/D ... 01320D.pdf) page 252 shows which pins can be used as external interrupt.

marcelocrr
Posts: 24
Joined: 15 Oct 2012 16:11

Re: Simple external interrupt program

#9 Post by marcelocrr » 25 May 2018 15:42

Yes, you must use int2 with rf8. See datasheet pag. 251.

Marcelo Rilko

pepper
Posts: 6
Joined: 06 May 2018 17:35

Re: Simple external interrupt program

#10 Post by pepper » 26 May 2018 14:58

Alright, thanks a lot for that. But i still can't get it to work with theses changes...

Code: Select all

int flag=0;
void main(){
ANSELA=0;
ANSELF=0;
TRISA=0;
LATA=0;
TRISF=1;         //button input

  Unlock_IOLOCK();
  PPS_Mapping(_RPF8, _INPUT, _INT2);
//RPINR0bits.INT1R = 58;
  Lock_IOLOCK();

  IFS0.INT2IF=0;     //clear interrupt flag
  INTCON.INT2EP=0;   //interrupt edge
  IPC3bits.INT2IP=1;     //interrupt priority
  IEC0.INT2IE=1;     //enable external interrupt

   EnableInterrupts();
               while(1){
                if (flag==1){
                flag=0;
                LATA=~PORTA;
                }
               }
}

 void EXT_INT2() iv IVT_EXTERNAL_2 ics ICS_AUTO
{
   flag=1;
   IFS0.INT2IF=0;
}

JairHdez
Posts: 16
Joined: 24 Feb 2017 19:25

Re: Simple external interrupt program

#11 Post by JairHdez » 28 May 2018 18:06

try INT2R = 0x0B; instead of

Code: Select all

Unlock_IOLOCK();
  PPS_Mapping(_RPF8, _INPUT, _INT2);
//RPINR0bits.INT1R = 58;
  Lock_IOLOCK();

pepper
Posts: 6
Joined: 06 May 2018 17:35

Re: Simple external interrupt program

#12 Post by pepper » 02 Jun 2018 10:31

I found the error. I didn't initialise F8 as input properly.

Code: Select all

TRISF=0x100;
is the correct way to do it.

thanks

Post Reply

Return to “mikroC PRO for PIC32 General”