From f75283e440df24292d51b7b10f72a4d17c6302f0 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 24 Mar 2022 15:19:31 +0100 Subject: interrupts working (finally) --- Makefile | 1 + src/main.c | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 819c74b..de10ee6 100644 --- a/Makefile +++ b/Makefile @@ -5,3 +5,4 @@ USE_ST_CMSIS = true # Include the main makefile include ./STM32-base/make/common.mk +CXX = $(CC) diff --git a/src/main.c b/src/main.c index 241f369..98de161 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,4 @@ -#ifdef __cplusplus -extern "C" { -#endif - +#include #include "stm32f091xc.h" // GPIO A @@ -74,22 +71,20 @@ void shield_config() { TIM3->CR1 |= TIM_CR1_CEN; // enable counter } - void toggle_direction() { led_direction = !led_direction; } void EXTI4_15_IRQHandler(void) { - // toggle_direction(); - led_direction = !led_direction; - return; + toggle_direction(); + EXTI->PR |= EXTI_PR_PIF8; } void interrupt_setup() { RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN; - SYSCFG->EXTICR[PINOUT_BTN / 4] &= ~(0xF << ((PINOUT_BTN % 4) * 4)); - SYSCFG->EXTICR[PINOUT_BTN / 4] |= (0x1 << ((PINOUT_BTN % 4) * 4)); + SYSCFG->EXTICR[2] &= ~(SYSCFG_EXTICR3_EXTI8_Msk); + SYSCFG->EXTICR[2] |= (SYSCFG_EXTICR3_EXTI8_PB); EXTI->IMR |= (1 << PINOUT_BTN); EXTI->RTSR &= ~(1 << PINOUT_BTN); @@ -146,7 +141,7 @@ void dumb_delay() { * It uses the channel 1 capture/compare register to check if the time (in * milliseconds) has expired. */ -int timer_delay(unsigned short millis) { +void timer_delay(unsigned short millis) { TIM3->CCR1 = millis; // set delay amount TIM3->CNT = 0; // reset timer TIM3->SR &= ~(TIM_SR_CC1IF); // reset capture/compare output @@ -157,6 +152,8 @@ int main() { shield_config(); interrupt_setup(); + // int test = 0; + while (1) { // if ((TIM3->SR & TIM_SR_CC1IF) > 0) { // toggle_direction(); @@ -166,9 +163,8 @@ int main() { // } timer_delay(100); next_led(); - } -} + // test = (test + 1) % 5; -#ifdef __cplusplus + // if (test == 0) toggle_direction(); + } } -#endif -- cgit v1.2.3