#include "timer_a1.h" #include "inc/msp432p401r.h" void (*timer_a1_task)(void); // user function // Activate Timer A1 interrupts to run user task periodically // 16 bits period in units (24/SMCLK, with SMCLK 12 MHz -> 2us) void TimerA1Init(void (*task)(void), uint16_t period) { timer_a1_task = task; // Stop timer, SMCLK, /4 divider TIMER_A1->CTL = 0x0280; // Configure CCR0 TIMER_A1->CCTL[0] = 0x0010; // Compare mode, enable interrupt TIMER_A1->CCR[0] = (period - 1); // Clock divider (EX0 register) TIMER_A1->EX0 = 0x0005; // /6 divider (additional to the /4 above) // NVIC configuration NVIC->IP[3] = (NVIC->IP[3]&0xFFFFFF00)|0x00000040; // priority 2 NVIC->ISER[0] = 0x00001000; // enable interrupt 12 in NVIC // Enable timer interrupts and start in up mode TIMER_A1->CTL |= 0x0014 | 0x0020; // reset, up mode, enable interrupts NVIC_EnableIRQ(TA1_0_IRQn); } void TA1_0_IRQHandler(void) { TIMER_A1->CCTL[0] &= ~0x0001; timer_a1_task(); }