PIC32MX Interrupt crashes system

Hi Robert,

I found that the whole Harmony thing was a bit of a pain.

  1. Make sure that in the configuration bits you have:
    #pragma config FSRSSEL = PRIORITY_7

By default Harmony sets that as 0 which crashes the whole thing at the first interrupt.

  1. For the external pin interrupt, to take an easy example, I have the following code Obviously you need to initialise the interrupt controller and the interrupt priority settings for it to fire.

In the a name.c file

void vInitExternalInterrupt( void)
{
    IPC1SET = ((2<<_IPC1_INT1IP_POSITION)&_IPC1_INT1IP_MASK)| 0x0;
    INTCONCLR = _INTCON_INT1EP_MASK; //External interrupt on falling edge
    IFS0CLR = _IFS0_INT1IF_MASK; // Clear the external interrupt flag
    IEC0SET = _IEC0_INT1IE_MASK; // Enable the external interrupt
}

void __attribute__( (interrupt(IPL0AUTO), vector(_EXTERNAL_1_VECTOR))) vExternalInterruptWrapper( void );

void vExternalInterruptHandler( void )
{
    BaseType_t bTaskWasWoken = pdFALSE;
    IFS0CLR = _IFS0_INT1IF_MASK; // Clear the interrupt
    // Post a message into a queue using the FromISR variant
    portYIELD_FROM_ISR(bTaskWasWoken);
}

In a name_isr.s file (assembly, yes :frowning: )

#include <xc.h>
#include <sys/asm.h>
#include "ISR_Support.h"

	.set	nomips16
	.set 	noreorder
 	
	.extern vExternalInterruptHandler
	.extern xISRStackTop
	.global	vExternalInterruptWrapper

	.set	noreorder
	.set 	noat
	.ent	vExternalInterruptWrapper

vExternalInterruptWrapper:

	portSAVE_CONTEXT
	jal vExternalInterruptHandler
	nop
	portRESTORE_CONTEXT

	.end	vExternalInterruptWrapper

Hope this helps solve your problem.

1 Like