From 6c90271b1d20235d917509454dc1b4e4a66f13f6 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 27 Sep 2021 12:09:19 +0200 Subject: Cleanup Code --- src/main.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 1027d18..f8b803b 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,6 @@ #include -#include #include #include #include @@ -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 } -- cgit v1.2.3-70-g09d2