我正在尝试使用我的 NUCLEO 板(PC13)上的用户按钮编写一个中断代码来触发 LED(PB14)。然而,正如我从调试器中观察到的那样,第 13 行的挂起位始终为 1,而根本没有按下按钮。
EX
ti->PR1 = 1<<13 仍在执行,但无法清除未决位。
有人可以指出我的问题吗?这是我的代码。
谢谢你。
- /*--Header--------------------------------------------------------------------------------*/
- #include
- #include
- #include "STM32l4r5xx.h"
- /*--Define--------------------------------------------------------------------------------*/
- /*--Global-Variable---------------------------------------------------------------------- */
- /*--Function Prototypes-------------------------------------------------------------------*/
- void initPort (void);
- void Blink(void);
- /*--Main----------------------------------------------------------------------------------*/
- int main()
- {
- initPort();
- while(1)
- {
- }
- } // EO Main
- /*--Function------------------------------------------------------------------------------*/
- /************************************************/
- /* Name: initPort */
- /*-Initiating PC13 as input/interrupt */
- /*-Initiating PB14 as LED red */
- /* */
- /************************************************/
- void initPort(void)
- {
- RCC->AHB2ENR |= 0x04;// Enable GPIO port D
- GPIOC->MODER &= ~(1<<26);
- GPIOC->MODER &= ~(1<<27); // Enable PC13 as input - Button
- EXTI->RTSR1 |= 0x1<<13; // Enable EXTI15-PD13 triggers in raising edge
- EXTI->IMR1 |= 0x1<<13; // Un-mask EXTI15 to enable the interrupt in PD13
- NVIC->ISER[1] |= 1<<8; //Enable EXTI15_10 - vector position 40
- RCC->AHB2ENR |= 1<<1; //Enable GPIO port B
- GPIOB->MODER &= ~(1<<29);
- GPIOB->MODER |= 1<<28; //Set PD14 as general output LED3
- }
- void Blink(void)
- {
- GPIOB->ODR ^= 1<<14; // toggle pin PB14 - LED3
- for(int i=0; i<10000; i++);
- }
- void EXTI15_10_IRQHandler (void)
- {
- if (EXTI->PR1 & 1<<13) // check if the pending register is on
- {
- EXTI->PR1 = 1<<13; // clear the pending register by writing 1 to it
- }
- Blink();
- }