Estoy trabajando con un stm32f103 y estoy tratando de hacer la interrupción externa. Mi código es:
void delay(unsigned int counts);
//---------------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_Led.GPIO_Pin = LED_PIN;
GPIO_Led.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Led.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LED_PORT, &GPIO_Led);
LED_OFF;
delay(500);
LED_ON;
// Enable Clock for AFIOEN
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
// Enable Clock for IOPBEN
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
// Set PB1 as input with pullup
GPIOB->CRL &= ~((1 << 4) | (1 << 5));
GPIOB->CRL |= (1 << 7);
GPIOB->CRL &= ~(1 << 6);
GPIOB->ODR |= (1 << 1);
// Source input for EXTI1 is PB1
AFIO->EXTICR[0] |= AFIO_EXTICR1_EXTI1_PB;
// Interrupt request from Line 1 is not masked => enabled
EXTI->IMR |= (1 << 1);
// Rising edge
EXTI->RTSR |= (1 << 1);
NVIC_InitTypeDef NVIC_InitStruct;
// Add IRQ vector to NVIC
// PB1 is connected to EXTI_Line1, which has EXTI1_IRQn vector
NVIC_InitStruct.NVIC_IRQChannel = EXTI1_IRQn;
// Set priority
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x0f;
// Set sub priority
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x0f;
// Enable interrupt
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
delay(500);
LED_OFF;
// Infinite loop
while (1)
{
LED_TOGGLE;
delay(500);
}
}
//---------------------------------------------------------------------------------------
void delay(unsigned int counts)
{
volatile unsigned int i = 0, j = 0;
while (i < counts)
{
j = 0;
while (j < 0x1AFF)
{
j++;
}
i++;
}
}
//---------------------------------------------------------------------------------------
void EXTI1_IRQHandler()
{
/* Make sure that interrupt flag is set */
if (EXTI_GetITStatus(EXTI_Line1) != RESET)
{
LED_TOGGLE;
/* Clear interrupt flag */
EXTI_ClearITPendingBit(EXTI_Line1);
}
}
Esa es la parte principal de mi código. LED_ON, LED_OFF y LED_TOGGLE son solo algunas definiciones. Funcionan bien.
El problema es: Si hay un flanco ascendente en el pin PB1, el stm32 no salta a la subrutina IRQ. Así que el stm32 se atascó.
¿Alguien sabe cuál es el problema? No tengo ninguna idea.