This blog post explains interrupt programming with cortex m4 development board
Steps to Configure Interrupt
- Configure pin P2.10 as EINT0 pin using IOCON register P2_10
- Configure the pin P2.10 as input
- Select edge triggering mode and select falling edge
- Enable interrupt and Set Priority
- Clear the Interrupt Flag initially
- Go to the interrupt service routine and do some task
- Clear the Interrupt
Interrupt using Cortex m4 -C Source code
#include "LPC407x_8x_177x_8x.h"
unsigned int count=0;
void delay_ms(long ms);
void Init_LED(void);
void Init_EINT0(void);
void EINT0_IRQHandler(void)
{
//6. the interrupt service routine
LPC_SC->EXTINT |= 1; //7. Clear Interrupt flag
count++;
while((LPC_GPIO2->PIN & 0x400)==0);
}
int main(void)
{
Init_LED();
Init_EINT0();
while(1)
{
LPC_GPIO4->PIN = count;
}
}
void delay_ms(long ms) // delay 1 ms per count @ CCLK 120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}
void Init_LED(void)
{
//Set the PCGPIO bit
LPC_SC->PCONP |= (1<<15);
//Configure pins P4.0 to P4.7 as GPIO pins
LPC_IOCON->P4_0 = 0;
LPC_IOCON->P4_1 = 0;
LPC_IOCON->P4_2 = 0;
LPC_IOCON->P4_3 = 0;
LPC_IOCON->P4_4 = 0;
LPC_IOCON->P4_5 = 0;
LPC_IOCON->P4_6 = 0;
LPC_IOCON->P4_7 = 0;
//Configure the pins P4.0 to P4.7 as output
LPC_GPIO4->DIR= 0xFF;
}
void Init_EINT0(void)
{
//1. Configure pin P2.10 as EINT0 pin
LPC_IOCON->P2_10 = 1;
//2. Configure the pin P2.10 as input
LPC_GPIO2->DIR &= ~(1<<10);
//3. Select Edge Triggering Mode and Select Falling Edge
LPC_SC->EXTMODE = 1;
LPC_SC->EXTPOLAR= 0;
//4. Enable Interrupt and Set Priority
NVIC->ISER[0] |= (1<<18); //Enable EINT0
NVIC->IP[4] |= (0x3<<19); //Interrupt Priority 0-High, 31-low
//5. Clear Interrupt Flag
LPC_SC->EXTINT = 1;
}
Leave a Comment