Skip to main content
MHMallek
Associate II
October 27, 2019
Solved

Hello!! what is wrong ? I want to do an external interrupt with button (gpio A0) to turn on the led (gpio D14) (STM32F407DISC) and do not work..

  • October 27, 2019
  • 4 replies
  • 1025 views

void init_led(){

RCC->AHB1ENR|=0x8;

GPIOD->MODER|=0x10000000;

}

void led_on(){

GPIOD->ODR |= 0x4000;

}

void led_off(){

GPIOD->ODR &= 0xBFFF;

}

void init_button(){

RCC->AHB1ENR|=0X1; //ENABLE CLOCK TO GPIOA

GPIOA->MODER &= ~0x03; // make gpioa0 mode input

EXTI->FTSR |=0x01;

EXTI->IMR |=0x1;

// EXTI->EMR |=0x1;

NVIC->ISER[0] |=(1<EXTI0_IRQn);

}

void EXTI0_IRQHandler(){

if ((EXTI->PR & 0x01)){

EXTI->PR = 0x01;

led_on();

}

}

void init_syscfg(){

RCC->APB2ENR|=0x4000;

(*((uint32_t*)0x40013808)) &= ~0x15;

}

int main(void)

{

init_button();

init_syscfg();

init_led();

while (1)

{

}

}

This topic has been closed for replies.
Best answer by Tesla DeLorean

If you want to program like this you need to be able to user a debugger to check your work and cross check with the reference manual.

Use a shift here

NVIC->ISER[0] |=(1<EXTI0_IRQn);

4 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
October 28, 2019

If you want to program like this you need to be able to user a debugger to check your work and cross check with the reference manual.

Use a shift here

NVIC->ISER[0] |=(1<EXTI0_IRQn);

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
MHMallek
MHMallekAuthor
Associate II
October 28, 2019

thanks, this is not the problem, it seems like i forget something in the configuration.

turboscrew
Senior III
October 28, 2019

Check this: (*((uint32_t*)0x40013808)) &= ~0x15;

It seems to say : SYSCFG_EXTICR1.EXTI1 &= 0%1110, SYSCFG_EXTICR1.EXTI0 &= 0%1010

What should be left? Maybe you meant to write 15 (decimal, not hex)?

MHMallek
MHMallekAuthor
Associate II
October 28, 2019

you're right, i correct it but it still not work.

0690X00000ArKgXQAV.png