0

I am using PIC32MZ2048ECH144. I have two switches connected to RH8(pin Number 81) and RH9(pin Number 82). I do not see any option in MHC to set interrupt at pin level, therefore I get the ISR generated for the port-H. I need the ISRs for each pin to be invoked separately. Hence, in "system_init.c", in "SYS_Initialize" function I added the following lines,

PLIB_PORTS_PinChangeNoticePerPortEnable(PORTS_ID_0, PORT_CHANNEL_H, PORTS_BIT_POS_8); PLIB_PORTS_PinChangeNoticePerPortEnable(PORTS_ID_0, PORT_CHANNEL_H, PORTS_BIT_POS_9);

The ISR generated by MHC in "system_interrupt.c":

    void __ISR(_CHANGE_NOTICE_H_VECTOR, ipl3AUTO) _IntHandlerChangeNotification_PortH1(void)
    {
        PLIB_INT_SourceFlagClear(INT_ID_0,INT_SOURCE_CHANGE_NOTICE_H);
        APP_SwitchChangeNoticed();  
    }

I replaced the above ISR macro with the below lines:

    void __ISR(_ADC1_DATA22_VECTOR, ipl3AUTO) _IntHandlerChangeNotification_PortH1(void)
    {
        PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_CHANGE_NOTICE);
        APP_SwitchChangeNoticed();
    }

    void __ISR(_ADC1_DATA23_VECTOR, ipl3AUTO) _IntHandlerChangeNotification_PortH(void)
    {   
       PLIB_INT_SourceFlagClear(INT_ID_0,INT_SOURCE_CHANGE_NOTICE_H);
        test1();  
    }

This did not work out. I referred the link http://microchip.wikidot.com/faq:78. I feel I am wrong in choosing the vector numbers for the ISR macros from "/pic32mx/include/proc/p32mz2048ech144.h". (I used _ADC1_DATA22_VECTOR and _ADC1_DATA23_VECTOR thinking that the values against them 81 and 82 are pin numbers, which again did not work.) Any help or hints on how to set pin level interrupts(2 pins on the same port) would be really great! Kindly apologize for any mistakes in my post.

Thanks in advance.

  • Most likely you have to check a flag register from inside the ISR to see which port triggered the interrupt, then execute pin-specific code from there. – Lundin Jun 09 '16 at 07:35
  • I think the ISR with the vector(_CHANGE_NOTICE_H_VECTOR) itself is triggered only if there is a change in the H port. So in this case, I can directly use the pin-specific code inside the ISR. – NewBieToµC Jun 09 '16 at 09:18

1 Answers1

1

The short answer is that what you are asking for cant be achieved directly with two separate ISRs. There is only one change notification ISR vector available for the whole H port. You would normally achieve what you are looking for with an added software check to determine which of your two pins is in a different state. Another method is to simple move your signal to another port (if your board is not finalized).

The name you give the function has no bearing on what the ISR will react to. The real magic comes in the __ISR macro arguments.

For example:

void __ISR(_CHANGE_NOTICE_H_VECTOR, ipl3AUTO) _IntHandler1234()

Notice the _CHANGE_NOTICE_H_VECTOR; it signifies that this interrupt service routine will be called when the change notification interrupt happens on port H.

Mathieu L.
  • 438
  • 2
  • 8
  • Your answer is really helpful. Thank you! I will not be able to change the port as the board is finalized. But I can use the software check, by storing the previous state of each pin and check with the current state. Thank you for the quick reply :) – NewBieToµC Jun 08 '16 at 21:05
  • I have a design that uses the PIC32MX series which only has one CN ISR. I use sw to determine which pin has changed on a set of 4 CN pins. It's do-able. – blsmit5728 Jun 10 '16 at 17:51