paolo della vedova
/
interrupt_test_stm32_nucle
interrupt test EXTI stm32 nucleo
main.cpp@2:70bfc841a60f, 2015-10-27 (annotated)
- Committer:
- c128
- Date:
- Tue Oct 27 04:47:07 2015 +0000
- Revision:
- 2:70bfc841a60f
- Parent:
- 1:d049e15030ca
x
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
c128 | 0:c5e2a50f0d5d | 1 | #include "mbed.h" |
c128 | 2:70bfc841a60f | 2 | #include "stm32f4xx_hal.h" |
c128 | 0:c5e2a50f0d5d | 3 | #include "stm32f4xx.h" |
c128 | 2:70bfc841a60f | 4 | #include "stm32f4xx_hal_gpio.h" |
c128 | 2:70bfc841a60f | 5 | |
c128 | 2:70bfc841a60f | 6 | |
c128 | 2:70bfc841a60f | 7 | static GPIO_InitTypeDef GPIO_InitStruct; |
c128 | 2:70bfc841a60f | 8 | |
c128 | 2:70bfc841a60f | 9 | int16_t count1 = 1000; |
c128 | 2:70bfc841a60f | 10 | |
c128 | 0:c5e2a50f0d5d | 11 | void EXTI0_IRQHandler(void) |
c128 | 0:c5e2a50f0d5d | 12 | { |
c128 | 2:70bfc841a60f | 13 | HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn); |
c128 | 2:70bfc841a60f | 14 | HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); |
c128 | 2:70bfc841a60f | 15 | { |
c128 | 2:70bfc841a60f | 16 | /* EXTI line interrupt detected */ |
c128 | 2:70bfc841a60f | 17 | if(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_0) != RESET) |
c128 | 2:70bfc841a60f | 18 | { |
c128 | 2:70bfc841a60f | 19 | __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0); |
c128 | 2:70bfc841a60f | 20 | HAL_GPIO_EXTI_Callback(GPIO_PIN_0); |
c128 | 2:70bfc841a60f | 21 | } |
c128 | 0:c5e2a50f0d5d | 22 | } |
c128 | 2:70bfc841a60f | 23 | } |
c128 | 2:70bfc841a60f | 24 | |
c128 | 0:c5e2a50f0d5d | 25 | void HAL_GPIO_EXTI_Callback (uint16_t GPIO_Pin) |
c128 | 0:c5e2a50f0d5d | 26 | { |
c128 | 0:c5e2a50f0d5d | 27 | if (GPIO_Pin == GPIO_PIN_0) { |
c128 | 2:70bfc841a60f | 28 | count1 = 100; |
c128 | 0:c5e2a50f0d5d | 29 | } |
c128 | 0:c5e2a50f0d5d | 30 | } |
c128 | 1:d049e15030ca | 31 | |
c128 | 0:c5e2a50f0d5d | 32 | int main() |
c128 | 0:c5e2a50f0d5d | 33 | { |
c128 | 0:c5e2a50f0d5d | 34 | HAL_Init(); |
c128 | 1:d049e15030ca | 35 | |
c128 | 2:70bfc841a60f | 36 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
c128 | 0:c5e2a50f0d5d | 37 | GPIO_InitStruct.Pin = GPIO_PIN_0; //PA0 as interrupt test |
c128 | 0:c5e2a50f0d5d | 38 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; |
c128 | 2:70bfc841a60f | 39 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
c128 | 0:c5e2a50f0d5d | 40 | GPIO_InitStruct.Speed = GPIO_SPEED_FAST; |
c128 | 0:c5e2a50f0d5d | 41 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
c128 | 2:70bfc841a60f | 42 | HAL_NVIC_SetPriority(EXTI0_IRQn, 3, 0); |
c128 | 0:c5e2a50f0d5d | 43 | HAL_NVIC_EnableIRQ(EXTI0_IRQn); |
c128 | 1:d049e15030ca | 44 | |
c128 | 2:70bfc841a60f | 45 | /* -2- Configure PA05 IO in output push-pull mode to |
c128 | 2:70bfc841a60f | 46 | drive external LED */ |
c128 | 2:70bfc841a60f | 47 | GPIO_InitStruct.Pin = GPIO_PIN_5; |
c128 | 2:70bfc841a60f | 48 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
c128 | 2:70bfc841a60f | 49 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
c128 | 2:70bfc841a60f | 50 | GPIO_InitStruct.Speed = GPIO_SPEED_FAST; |
c128 | 2:70bfc841a60f | 51 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
c128 | 2:70bfc841a60f | 52 | |
c128 | 0:c5e2a50f0d5d | 53 | while (1) { |
c128 | 2:70bfc841a60f | 54 | HAL_NVIC_DisableIRQ(EXTI0_IRQn); |
c128 | 2:70bfc841a60f | 55 | HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); |
c128 | 2:70bfc841a60f | 56 | |
c128 | 2:70bfc841a60f | 57 | /* Insert delay 100 ms */ |
c128 | 2:70bfc841a60f | 58 | HAL_Delay(count1); |
c128 | 2:70bfc841a60f | 59 | HAL_NVIC_EnableIRQ(EXTI0_IRQn); |
c128 | 1:d049e15030ca | 60 | |
c128 | 0:c5e2a50f0d5d | 61 | } |
c128 | 1:d049e15030ca | 62 | |
c128 | 1:d049e15030ca | 63 | } |
c128 | 2:70bfc841a60f | 64 | |
c128 | 2:70bfc841a60f | 65 |