2020-12-14 12:44 PM
Hello, I am beginner and I am trying to write a code without HALL. The goal is switch LED when button press using interrupts. I check the button and the LED separately. Everything works fine. But interrupt code don't want to. What am I doing wrong? Using Keil5.
#include "stm32f10x.h" // Device header
static int temp = 0;
void EXTI0_IRQHandler(void)
{
EXTI->PR |= 1 << 0;
temp ^= 1;
}
int main()
{
//initialize the clock for the GPIOC and GPIOA
RCC->APB2ENR |= (1 << 4);
RCC->APB2ENR |= (1 << 2);
//configure pin 13 on GPIO C
GPIOC->CRH |= ((1 << 20) | (1 << 21)); //output 50MHz
GPIOC->CRH &= ~((1 << 22) | (1 << 23)); //general purpose output
//configure button pin
//GPIOA pin 0 input pullup
GPIOA->CRL &= ~(1 << 1 | 1 << 0);
GPIOA->CRL |= 1 << 3;
GPIOA->CRL &= ~(1 << 2);
GPIOA->ODR |= 1 << 0;
//configure interrupt
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
AFIO->EXTICR[0] = AFIO_EXTICR1_EXTI0_PA;
EXTI->FTSR |= 1 << 0;
EXTI->IMR |= 1 << 0; //enable interrupt
NVIC_EnableIRQ(EXTI0_IRQn); //
NVIC_SetPriority(EXTI0_IRQn, 0);
while(1)
{
if(temp)
GPIOC->BSRR = 1 << 13;
else
GPIOC->BSRR = 1 << (13 + 16);
}
return 0;
}
2020-12-14 12:54 PM
I don't know why, but after few hours of trying it suddenly start work. I haven't change the code that I wrote here. If it possible - delete this question. I am sorry.