#include "systick.h" #include "inc/msp432p401r.h" void SysTickInit(void) { SysTick->LOAD = 0x00FFFFFF; // maximum reload value SysTick->CTRL = 0x00000005; // enable SysTick with no interrupts } // Assumes 48 MHz bus clock void SysTickWait(uint32_t delay_ticks) { // 1. Write a desired delay_ticks value into the SysTick->LOAD register and subtract 1 from it, SysTick->LOAD = delay_ticks - 1; // 2. Clear the SysTick->VAL counter value, which also clears the COUNT bit, SysTick->VAL = 0; // 3. Wait for the COUNT bit in the SysTick->CTRL register to be set. while((SysTick->CTRL & 0x00010000) == 0); // wait for COUNTFLAG // any write to CVR clears it and COUNTFLAG in CSR } void SysTickWait1us(uint32_t times) { uint32_t count = (48 * times) / 0x00FFFFFF; uint32_t rem = (48 * times) % 0x00FFFFFF; uint32_t i; for (i = 0; i < count; ++i) { SysTickWait(0x00FFFFFF); // wait max } SysTickWait(rem); }