I'm trying to figure out how to make a timer call a function (I'm trying to do this without a library for the sake of getting familiar with the datasheet and microcontroller), I have this (part from datasheet, with attempted fixes from other sources), but it doesn't seem to work. Anyone know where I'm going wrong? Thanks for any help:)
#include <Arduino.h>
#define REG_SET_BIT(reg,index) ((reg)|=(1<<index))
#define REG_CLEAR_BIT(reg,index) ((reg)&=~(1<<index))
bool isLEDoff=true;
void setup()
{
pinMode(PIN_LED,OUTPUT);
digitalWrite(PIN_LED,isLEDoff);
REG_SET_BIT(RCC->APB1LENR,RCC_APB1LENR_TIM2EN); //Enable TIM2 clock
//240,000,000/24,000=10,000 Counts for 1 Second
TIM2->PSC=24000-1; //Set prescaller
TIM2->ARR=10000-1; //Set count value
REG_SET_BIT(TIM2->EGR,TIM_EGR_UG);
//Enable TIM2 interrupt handler in NVIC
NVIC_EnableIRQ(TIM2_IRQn);
NVIC_SetPriority(TIM2_IRQn,0);
REG_CLEAR_BIT(TIM2->SR,TIM_SR_UIF); //Clear Status Register (seems to not continue w/o this)
REG_SET_BIT(TIM2->DIER,TIM_DIER_UIE); //Enable interrupt
REG_SET_BIT(TIM2->CR1,TIM_CR1_CEN); //Enable Timer
}
void loop()
{
}
void TIM2_IRQHandler(void)
{
REG_CLEAR_BIT(TIM2->SR,TIM_SR_UIF);
isLEDoff^=true;
digitalWrite(PIN_LED,isLEDoff);
}