Hello,
I have the following program to flash blue led on TM4C123.Blue led flashes as desired.
There is also an ISR which has to flash the red led when SW1 is pushed however i can not manage to enter into ISR code and the red led never flashes.
I am using CCS to debug the code and the "GPIO_PortF_Handler" is included into the startup file together with the "extern void GPIO_PortF_Handler(void);" definition
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#define NVIC_EN0_R (*((volatile uint32_t *)0xE000E100)) // IRQ 0 to 31 Set Enable Register
#define NVIC_PRI7_R (*((volatile uint32_t *)0xE000E41C)) // IRQ 28 to 31 Priority Register
#define GPIO_PORTF_DATA_R (*((volatile uint32_t *)0x400253FC))
#define GPIO_PORTF_DIR_R (*((volatile uint32_t *)0x40025400))
#define GPIO_PORTF_AFSEL_R (*((volatile uint32_t *)0x40025420))
#define GPIO_PORTF_PUR_R (*((volatile uint32_t *)0x40025510))
#define GPIO_PORTF_DEN_R (*((volatile uint32_t *)0x4002551C))
#define GPIO_PORTF_LOCK_R (*((volatile uint32_t *)0x40025520))
#define GPIO_PORTF_CR_R (*((volatile uint32_t *)0x40025524))
#define GPIO_PORTF_AMSEL_R (*((volatile uint32_t *)0x40025528))
#define GPIO_PORTF_PCTL_R (*((volatile uint32_t *)0x4002552C))
#define GPIO_PORTF_PDR_R (*((volatile uint32_t *)0x40025514))
#define GPIO_PORTF_IS_R (*((volatile uint32_t *)0x40025404))
#define GPIO_PORTF_IBE_R (*((volatile uint32_t *)0x40025408))
#define GPIO_PORTF_IEV_R (*((volatile uint32_t *)0x4002540C))
#define GPIO_PORTF_RIS_R (*((volatile uint32_t *)0x40025414))
#define GPIO_PORTF_ICR_R (*((volatile uint32_t *)0x4002541C))
#define GPIO_PORTF_IM_R (*((volatile uint32_t *)0x40025410))
#define PF4 (*((volatile uint32_t *)0x40025040))
#define PF3 (*((volatile uint32_t *)0x40025020))
#define PF2 (*((volatile uint32_t *)0x40025010))
#define PF1 (*(volatile uint32_t *)0x40025008))
#define PF0 (*((volatile uint32_t *)0x40025004))
#define GPIO_PORTF_DR2R_R (*((volatile uint32_t *)0x40025500))
#define GPIO_PORTF_DR4R_R (*((volatile uint32_t *)0x40025504))
#define GPIO_PORTF_DR8R_R (*((volatile uint32_t *)0x40025508))
#define GPIO_LOCK_KEY 0x4C4F434B // Unlocks the GPIO_CR register
#define SYSCTL_RCGC2_R (*((volatile uint32_t *)0x400FE108))
#define SYSCTL_RCGC2_GPIOF 0x00000020 // port F Clock Gating Control
void PortF_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F
delay = SYSCTL_RCGC2_R; // allow time for clock to start
GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock GPIO Port F
GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0
// only PF0 needs to be unlocked, other bits can't be locked
GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog on PF
GPIO_PORTF_PCTL_R = 0x00000000; // 4) PCTL GPIO on PF4-0
GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 in, PF3-1 out
GPIO_PORTF_AFSEL_R = 0x00; // 6) disable alt funct on PF7-0
GPIO_PORTF_PUR_R = 0x11; // enable pull-up on PF0 and PF4
GPIO_PORTF_DEN_R = 0x1F; // 7) enable digital I/O on PF4-0
GPIO_PORTF_IS_R &= ~0x10;
GPIO_PORTF_IBE_R &= ~0x10;
GPIO_PORTF_IEV_R &= ~0x10;
GPIO_PORTF_ICR_R &= 0x10;
GPIO_PORTF_IM_R |= 0x10;
NVIC_PRI7_R = (NVIC_PRI7_R&0xFF00FFFF) | 0x00A00000;
NVIC_EN0_R = 0x40000000;
IntMasterEnable();
}
volatile uint32_t Led;
void Delay(void){unsigned long volatile time;
time = 145448; // 0.1sec
while(time){
time--;
}
}
int main(void){
PortF_Init(); // make PF1 out (PF1 built-in LED)
while(1){
Led = GPIO_PORTF_DATA_R; // read previous
Led = Led^0x04; // toggle red LED, PF1
GPIO_PORTF_DATA_R = Led; // output
Delay();
}
}
void GPIO_PortF_Handler (void){
GPIO_PORTF_ICR_R = 0x10;
Led = (GPIO_PORTF_DATA_R) | 0x02;
}