diff options
-rw-r--r-- | src/main.c | 33 |
1 files changed, 18 insertions, 15 deletions
@@ -2,7 +2,6 @@ #include <libopencm3/stm32/rcc.h> -#include <libopencm3/stm32/flash.h> #include <libopencm3/stm32/gpio.h> #include <libopencm3/stm32/timer.h> #include <libopencm3/cm3/nvic.h> @@ -10,10 +9,11 @@ static void clock_init(void); static void gpio_init(void); -void tim2_isr(void); static void nvic_init(void); static void timer_init(void); +void tim2_isr(void); + void main(void) { @@ -43,13 +43,6 @@ static void gpio_init(void) } -void tim2_isr(void) -{ - gpio_toggle(GPIOC, GPIO13); - TIM_SR(TIM2) &= ~TIM_SR_UIF; // clear interrrupt flag -} - - static void nvic_init(void) { nvic_enable_irq(NVIC_TIM2_IRQ); @@ -59,10 +52,20 @@ static void nvic_init(void) static void timer_init(void) { - gpio_set(GPIOC, GPIO13); - TIM_CNT(TIM2) = 1; // set start value - TIM_PSC(TIM2) = 1440; // set prescaler - TIM_ARR(TIM2) = 50000; // interrupt value - TIM_DIER(TIM2) |= TIM_DIER_UIE; // update interrupt enable - TIM_CR1(TIM2) |= TIM_CR1_CEN; // enable timer + // set LED on + gpio_clear(GPIOC, GPIO13); + + // setup timer + timer_set_counter(TIM2, 1); + timer_set_prescaler(TIM2, 1440); + timer_set_period(TIM2, 50000); + timer_enable_irq(TIM2, TIM_DIER_UIE); // set action to trigger interrupt + timer_enable_counter(TIM2); +} + + +void tim2_isr(void) +{ + gpio_toggle(GPIOC, GPIO13); + TIM_SR(TIM2) &= ~TIM_SR_UIF; // clear interrrupt flag } |