paolo della vedova
/
interrupt_test_stm32_nucle
interrupt test EXTI stm32 nucleo
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "stm32f4xx_hal.h" 00003 #include "stm32f4xx.h" 00004 #include "stm32f4xx_hal_gpio.h" 00005 00006 00007 static GPIO_InitTypeDef GPIO_InitStruct; 00008 00009 int16_t count1 = 1000; 00010 00011 void EXTI0_IRQHandler(void) 00012 { 00013 HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn); 00014 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); 00015 { 00016 /* EXTI line interrupt detected */ 00017 if(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_0) != RESET) 00018 { 00019 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0); 00020 HAL_GPIO_EXTI_Callback(GPIO_PIN_0); 00021 } 00022 } 00023 } 00024 00025 void HAL_GPIO_EXTI_Callback (uint16_t GPIO_Pin) 00026 { 00027 if (GPIO_Pin == GPIO_PIN_0) { 00028 count1 = 100; 00029 } 00030 } 00031 00032 int main() 00033 { 00034 HAL_Init(); 00035 00036 __HAL_RCC_GPIOA_CLK_ENABLE(); 00037 GPIO_InitStruct.Pin = GPIO_PIN_0; //PA0 as interrupt test 00038 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 00039 GPIO_InitStruct.Pull = GPIO_NOPULL; 00040 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; 00041 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 00042 HAL_NVIC_SetPriority(EXTI0_IRQn, 3, 0); 00043 HAL_NVIC_EnableIRQ(EXTI0_IRQn); 00044 00045 /* -2- Configure PA05 IO in output push-pull mode to 00046 drive external LED */ 00047 GPIO_InitStruct.Pin = GPIO_PIN_5; 00048 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 00049 GPIO_InitStruct.Pull = GPIO_PULLUP; 00050 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; 00051 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 00052 00053 while (1) { 00054 HAL_NVIC_DisableIRQ(EXTI0_IRQn); 00055 HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); 00056 00057 /* Insert delay 100 ms */ 00058 HAL_Delay(count1); 00059 HAL_NVIC_EnableIRQ(EXTI0_IRQn); 00060 00061 } 00062 00063 } 00064 00065
Generated on Fri Jul 15 2022 02:08:16 by 1.7.2