I wanted to use timers in TM4C123GH6PM (in TIVA C series TM4C123G Launchpad evaluation kit). So I decided to use GPTM TimerA0 in periodic timer mode. I defined the address of the registers of GPTM and followed the steps given in the section 11.4.1 One-Shot/Periodic Timer Mode of the datasheet in page 722. I want a LED to blink after every 3 seconds (connected to PORT F-pin 1). But the LED is always ON. Are the address of the registers to which I am referring wrong? Or something else is the issue with the code?
//TIMER Registers
#define RCGCTIMER (*((volatile unsigned long *)0x400FE604))
#define GPTMCTL (*((volatile unsigned long *)0x4003000C)) //timer zero
#define GPTMCFG (*((volatile unsigned long *)0x40030000))
#define GPTMTAMR (*((volatile unsigned long *)0x40030004))
#define GPTMTAILR (*((volatile unsigned long *)0x40030028))
#define GPTMRIS (*((volatile unsigned long *)0x4003001C))
#define GPTMICR (*((volatile unsigned long *)0x40030024))
//PORT F Registers
#define GPIO_PORTF_DATA_R (*((volatile unsigned long*)0x400253FC))
#define GPIO_PORTF_DIR_R (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL_R (*((volatile unsigned long *)0x40025420))
#define GPIO_PORTF_DEN_R (*((volatile unsigned long *)0x4002551C))
#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))
#define SYSCTL_RCGC2_GPIOF 0x00000020 // port F Clock Gating Control
void initializeTimer()
{
RCGCTIMER |= 0x00000001; //To use a GPTM, the appropriate TIMERn bit must be set in the RCGCTIMER. Here it is TIMER0
//Periodic timer mode
GPTMCTL &=0xFFFFFFFE; //TAEN is set 0. Timer A is disabled.
GPTMCFG = 0x00000000; //Write the GPTM Configuration Register (GPTMCFG) with a value of 0x0000.0000
GPTMTAMR |=0x00000002; GPTMTAMR &=0xFFFFFFFE; //TAMR is set 0x2. Periodic Timer mode is used (first bit1 is set 1 and then bit0 is set 0 in two statements)
GPTMTAMR &= 0xFFFFFFEF; //TACDIR is set 0. The timer counts down.
GPTMTAILR = 0x02DC6C00; //TAILR is set to 48,000,000 Hz
GPTMCTL |=0x00000001; //TAEN is set 1. Timer A is enabled.
}
void initializePORTF()
{
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000020; // 1) F clock
delay = SYSCTL_RCGC2_R; // delay
GPIO_PORTF_DIR_R |= 0x02; // PF1 output
GPIO_PORTF_AFSEL_R &= 0x00; // No alternate function// 1) F clock
GPIO_PORTF_DEN_R |= 0x02; // Enable digital pins PF1
GPIO_PORTF_DATA_R |= 0x02; //PF1 Set to 1. LED is ON
}
int main()
{
initializeTimer();
initializePORTF();
while(1)
{
//did TATORIS in GPTMRIS become 1??
if((GPTMRIS | 0x00000001) == 1)
{
GPTMICR |= 0x00000001; //Set 1 to TATOCINT. Writing a 1 to this bit clears the TATORIS bit in the GPTMRIS register and the TATOMIS bit in the GPTMMIS register.
GPIO_PORTF_DATA_R ^= 0x02; //Toggle PF1. Toggle LED
}
}
}