paolo della vedova
/
interrupt_test_stm32_nucle
interrupt test EXTI stm32 nucleo
main.cpp@1:d049e15030ca, 2015-10-26 (annotated)
- Committer:
- c128
- Date:
- Mon Oct 26 10:12:47 2015 +0000
- Revision:
- 1:d049e15030ca
- Parent:
- 0:c5e2a50f0d5d
- Child:
- 2:70bfc841a60f
O;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
c128 | 0:c5e2a50f0d5d | 1 | #include "mbed.h" |
c128 | 0:c5e2a50f0d5d | 2 | #include "stm32f4xx.h" |
c128 | 0:c5e2a50f0d5d | 3 | #include "stm32f4xx_hal_tim_ex.h" |
c128 | 0:c5e2a50f0d5d | 4 | #include "stm32f4xx_hal_conf.h" |
c128 | 1:d049e15030ca | 5 | |
c128 | 1:d049e15030ca | 6 | |
c128 | 1:d049e15030ca | 7 | |
c128 | 0:c5e2a50f0d5d | 8 | int16_t count1 = 10; |
c128 | 1:d049e15030ca | 9 | |
c128 | 1:d049e15030ca | 10 | |
c128 | 0:c5e2a50f0d5d | 11 | void EXTI0_IRQHandler(void) |
c128 | 0:c5e2a50f0d5d | 12 | { |
c128 | 0:c5e2a50f0d5d | 13 | HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn); |
c128 | 0:c5e2a50f0d5d | 14 | HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); |
c128 | 0:c5e2a50f0d5d | 15 | } |
c128 | 1:d049e15030ca | 16 | |
c128 | 0:c5e2a50f0d5d | 17 | void HAL_GPIO_EXTI_Callback (uint16_t GPIO_Pin) |
c128 | 0:c5e2a50f0d5d | 18 | { |
c128 | 0:c5e2a50f0d5d | 19 | if (GPIO_Pin == GPIO_PIN_0) { |
c128 | 0:c5e2a50f0d5d | 20 | count1 = 0; |
c128 | 0:c5e2a50f0d5d | 21 | } |
c128 | 0:c5e2a50f0d5d | 22 | } |
c128 | 1:d049e15030ca | 23 | |
c128 | 0:c5e2a50f0d5d | 24 | int main() |
c128 | 0:c5e2a50f0d5d | 25 | { |
c128 | 0:c5e2a50f0d5d | 26 | HAL_Init(); |
c128 | 1:d049e15030ca | 27 | |
c128 | 0:c5e2a50f0d5d | 28 | GPIO_InitTypeDef GPIO_InitStruct; |
c128 | 0:c5e2a50f0d5d | 29 | __GPIOA_CLK_ENABLE(); |
c128 | 0:c5e2a50f0d5d | 30 | GPIO_InitStruct.Pin = GPIO_PIN_0; //PA0 as interrupt test |
c128 | 0:c5e2a50f0d5d | 31 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; |
c128 | 0:c5e2a50f0d5d | 32 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
c128 | 0:c5e2a50f0d5d | 33 | GPIO_InitStruct.Speed = GPIO_SPEED_FAST; |
c128 | 0:c5e2a50f0d5d | 34 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
c128 | 0:c5e2a50f0d5d | 35 | HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 1); |
c128 | 0:c5e2a50f0d5d | 36 | HAL_NVIC_EnableIRQ(EXTI0_IRQn); |
c128 | 1:d049e15030ca | 37 | |
c128 | 1:d049e15030ca | 38 | |
c128 | 0:c5e2a50f0d5d | 39 | while (1) { |
c128 | 1:d049e15030ca | 40 | |
c128 | 0:c5e2a50f0d5d | 41 | printf("loop%d\r\n", count1); |
c128 | 0:c5e2a50f0d5d | 42 | wait(1); |
c128 | 1:d049e15030ca | 43 | |
c128 | 1:d049e15030ca | 44 | |
c128 | 0:c5e2a50f0d5d | 45 | } |
c128 | 1:d049e15030ca | 46 | |
c128 | 1:d049e15030ca | 47 | } |
c128 | 1:d049e15030ca | 48 | |
c128 | 1:d049e15030ca | 49 |