Martin Johnson / gpio_test_ints

Dependencies:   STM32F3-Discovery

Files at this revision

API Documentation at this revision

Comitter:
MartinJohnson
Date:
Mon Apr 29 23:30:48 2019 +0000
Parent:
1:5d95bdb46dfd
Commit message:
External interrupt handler for the user button

Changed in this revision

STM32F3-Discovery.lib Show annotated file Show diff for this revision Revisions of this file
main.c Show annotated file Show diff for this revision Revisions of this file
--- a/STM32F3-Discovery.lib	Thu Apr 19 00:03:02 2018 +0000
+++ b/STM32F3-Discovery.lib	Mon Apr 29 23:30:48 2019 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/MartinJohnson/code/STM32F3-Discovery/#404f5a4f1385
+https://developer.mbed.org/users/MartinJohnson/code/STM32F3-Discovery/#f8e3e71af478
--- a/main.c	Thu Apr 19 00:03:02 2018 +0000
+++ b/main.c	Mon Apr 29 23:30:48 2019 +0000
@@ -10,24 +10,39 @@
 }
 
 void sysDelayMs(unsigned dly) {
+	//dly=dly;
 	sysTiming = dly;
 	while (sysTiming > 0) __wfi();
 
 }
 
+
+void EXTI0_IRQHandler() {
+	if(EXTI->PR & 1) {
+		GPIOE->ODR ^= 0xff00;
+		//EXTI->PR |= 1;
+	}
+}
+
 int main(void) {
     
     SysTick_Config((SystemCoreClock / 1000));
     RCC->AHBENR |= RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOA;    
+    RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
     GPIOE->MODER = (GPIOE->MODER&0xffff) | 0x55550000; // output mode for PE8-15
 	GPIOA->MODER = (GPIOA->MODER&0xfffffffc)  ; // input mode for PA0
-
+	SYSCFG->EXTICR[0] &= ~0xf;
+	EXTI->IMR |= 1; // int enable
+	EXTI->RTSR |= 1; // rising
+	EXTI->FTSR &= ~1; // falling
+	NVIC->IP[EXTI0_IRQn]=32; // Interrupt Priority, lower is higher priority
+	NVIC->ISER[EXTI0_IRQn >> 0x05] = 1 << (EXTI0_IRQn & 0x1F); // Interrupt enable
     GPIOE->BSRR=0xff00;
     sysDelayMs(500);
     int b=0;
 	while(1) {
     	GPIOE->BSRR=1<<(b+8);
-    	while(GPIOA->IDR&1);
+    	//while(GPIOA->IDR&1);
     	sysDelayMs(100);
     	GPIOE->BSRR=1<<(b+8+16);
     	b=(b+1)%8;