Hello,
I'm just starting out embedded programming and chose this launchpad to be my first. I'm using Keil to blink a LED within a 1 second interval (ON for 1 second, OFF for 1 second) by using the Systick timer (Main clock, no PLL). However, it seems like the LED is blinking in 0.5 second intervals.
Also, I tested in simulation mode using the logic analyzer in Keil, and according to the logic analyzer, the LED is blinking within 1 second intervals. I honestly have no idea what is going on.
Below is my code
#include "tm4c123gh6pm.h" // Port F LED #define LED_RED (1U << 1); #define LED_BLUE (1U << 2); #define LED_GREEN (1U << 3); void PortF_Init(void); void PLL_Init(void); void SysTick_Init(void); void Systick_delay(void); int main(){ PortF_Init(); SysTick_Init(); for(;;) { // Turn on RED LED GPIOF->DATA ^= LED_RED; Systick_delay(); } return 0; } // // Initializes Port F to allow SW1 as input, and RED, BLUE and GREEN LED as outut void PortF_Init(void) { SYSCTL->RCGCGPIO = (1U << 5); // Enable PortF Clock while( (SYSCTL->RCGCGPIO) == 0x00 ); // Wait for Clock to stabilize // Configure PF4 (SW1) as Input; PF1, PF2, PF3 as output GPIOF->DIR &= 0xFFFFFFEF; // PF4 As Input 0b 1110 1111 GPIOF->DIR |= 0x0000000E; // PF3, PF2, PF1 as output 0b 0000 1110 // Clear Alternate Functions to set GPIO pins as GPIO GPIOF->AFSEL = 0x00000000; // Enable Pull up Resistor on SW1 GPIOF->PUR |= (1U << 4); // Disable Analog Mode and Enable Digital Mode for GPIOF pins GPIOF->AMSEL &= 0x00000000; GPIOF->DEN |= 0x0000001E; // Digital Enable Port F pins 1 - 4 (bit[4:1]) } // // Initializes Systick timer void SysTick_Init(void) { // 0. Disable Systick SysTick->CTRL &= 0x00; // 1. Program the value in the STRELOAD register. SysTick->LOAD = 16000000U; // 2. Clear the STCURRENT register by writing to it with any value. SysTick->VAL = 0U; // 3. Configure the STCTRL register for the required operation. SysTick->CTRL |= (1U << 2); // Use System Clock (16 MHz) SysTick->CTRL |= (1U << 0); // Enable Systick } // // Delay Timer Using Systick // Will delay for 1 second void Systick_delay(void) { // Write to VAL to reset Counter SysTick->VAL = 16000000U; // Wait while count flag is still 0 while( (SysTick->CTRL & 0x00010000) == 0x00 ); }
If someone can give me some advice, it would be greatly appreciated. Thanks