Part Number: TM4C123GH6PM
Tool/software: Code Composer Studio
Hello all,
I am trying to run the project below on my development board and it suppose to blink the LED light until SW1 or SW2 is pressed. The prototype its suppose to use for the interrupt is "void GPIOF_Handler(void)". I am not sure if that is correct of how it is suppose use the interrupt correctly. As of right now when I press either button the LED just stalls in the current position it is at.
I am trying to figure out if I am missing a header file for the prototype or am I suppose to declare it at a different point in the code to make sure it runs.
If anyone can help me and or explain it, I would greatly appreciate it.
Thank you.
#include <stdint.h>
#include <tm4c123gh6pm.h>
#include <stdbool.h>
#include <hw_types.h>
#include <interrupt.h>
void delay_ms(int n);
bool IntMasterEnable(void);
bool IntMasterDisable(void);
extern void GPIOFIntHandler(void);
int main(void)
{
SYSCTL_RCGCGPIO_R |= 0x20; /* enable clock to PORTF */
/* PORTF0 has special function, need to unlock to modify */
GPIO_PORTF_LOCK_R = 0x4C4F434B; /* unlock commit register */
GPIO_PORTF_CR_R = 0x01; /* make PORTF0 configurable */
GPIO_PORTF_LOCK_R = 0; /* lock commit register */
/* configure PORTF for switch input and LED output */
GPIO_PORTF_DIR_R &= ~0x11; /* make PORTF4 input for switch */
GPIO_PORTF_DIR_R |= 0x0E; /* make PORTF3, 2, 1 output for LEDs */
GPIO_PORTF_DEN_R |= 0x1F; /* make PORTF-0 digital pins */
GPIO_PORTF_PUR_R |= 0x11; /* enable pull up for PORTF4, 0 */
/* configure PORTF4, 0 for falling edge trigger interrupt */
GPIO_PORTF_IS_R &= ~0x11; /* make bit 4, 0 edge sensitive */
GPIO_PORTF_IBE_R &= ~0x11; /* trigger is controlled by IEV */
GPIO_PORTF_IEV_R &= ~0x11; /* falling edge trigger */
GPIO_PORTF_ICR_R |= 0x11; /* clear any prior interrupt */
GPIO_PORTF_IM_R |= 0x11; /* unmask interrupt */
/* enable interrupt in NVIC and set priority to 3 */
NVIC_PRI30_R = 3 << 5; /* set interrupt priority to 3 */
NVIC_EN0_R |= 0x40000000; /* enable IRQ 30 ( D30 of ISER[0]) */
bool IntMasterEnable();
/* toggle the red LED (PF1) continuously */
while(1)
{
GPIO_PORTF_DATA_R |= 0x02;
delay_ms(500);
GPIO_PORTF_DATA_R &= ~0x02;
delay_ms(500);
}
}
/* SW1 is connected to PF4 pin, SW2 is connected to PF0. */
/* Both of them trigger PORTF interrupt */
void GPIOF_Handler(void)
{
int i;
volatile int readback;
/* toggle green LED (PF3) three times */
for (i = 0; i < 3; i++)
{
GPIO_PORTF_DATA_R |= 0x08;
delay_ms(500);
GPIO_PORTF_DATA_R &= ~0x08;
delay_ms(500);
}
GPIO_PORTF_ICR_R |= 0x11; /* clear the interrupt flag before return */
readback = GPIO_PORTF_ICR_R; /* a read to force clearing of interrupt flag */
}
/* delay n milliseconds (16 MHz CPU clock) */
void delay_ms(int n)
{
int i, j;
for(i = 0; i < n; i++)
for(j = 0; j < 3180; j++)
{} /* do nothing for 1 ms */
}
/* This function is called by the startup assembly code to perform system specific
* initialization tasks
*/
void SystemInit(void)
{
bool IntMasterDisable();
/* Grant coprocessor access */
/* This is required since TM4c123G has a floating point coprocessor */
NVIC_CPAC_R |= 0x00F00000;
}