-
Notifications
You must be signed in to change notification settings - Fork 12
SysTick
The code snippet below are address definitions used for the SysTick timer examples in this guide. Visit the STCTRL section of the TM4C123G datasheet for more info on the registers used for the SysTick timer. > SysTick is a timer feature that is available in all Cortex-M microcontrollers
#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010))
#define NVIC_ST_RELOAD_R (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018))
#define NVIC_ST_CTRL_COUNT 0x00010000 // Count flag
#define NVIC_ST_CTRL_CLK_SRC 0x00000004 // Clock Source
#define NVIC_ST_CTRL_INTEN 0x00000002 // Interrupt enable
#define NVIC_ST_CTRL_ENABLE 0x00000001 // Counter mode
#define NVIC_ST_RELOAD_M 0x00FFFFFF // Counter load value
void SysTick_Init(void){
NVIC_ST_CTRL_R = 0;
NVIC_ST_RELOAD_R = NVIC_ST_RELOAD_M;
NVIC_ST_CURRENT_R = 0;
NVIC_ST_CTRL_R = NVIC_ST_CTRL_ENABLE+NVIC_ST_CTRL_CLK_SRC;
}
void SysTick_Wait(unsigned long delay){
volatile unsigned long elapsedTime;
unsigned long startTime = NVIC_ST_CURRENT_R;
do{
elapsedTime = (startTime-NVIC_ST_CURRENT_R)&0x00FFFFFF;
}
while(elapsedTime <= delay);
}
-
- Calculate how long it takes (in seconds) for one clock tick to decrement
-
-
- 1 tick = (1/System Clock) * 10^9 nano seconds
-
- example: (1/80MHz) * 10^9 = 12.5 nano seconds
-
Note: The guides in these wiki are quick reference guides I made for myself and should not be used for teaching as they may contain errors that could misinform students. If you are a student, make sure you confirm everything you read on this wiki using the datasheet before fully committing to the information on this wiki.
TM4C123G (datasheet)
TM4C123G is a 32bit MCU based on the ARM® Cortex®-M4F architecture. Make sure to read C++ Support on TI Compilers if you plan on using C++