Need Help with NVIC Pending Register Not Reflecting Button Press on STM32L476RG
@Umesh Lokhande @Edison_ngunjiri @ZacckOsiemo just saw this question in another forum and thought you might be able to troubleshoot for the dev:
Subject: Need Help with NVIC Pending Register Not Reflecting Button Press on STM32L476RG
Message:
I'm currently working on a project where I'm writing a driver for my STM32 Nucleo L476RG board. I’m trying to test an interrupt using the user button on the board. Here's what I’ve done so far:
* Button Configuration:
* Configured the user button to trigger on the falling edge.
* Verified the GPIO pin is set as an input with the correct pull-up/pull-down configuration.
* EXTI Configuration:
* Mapped the EXTI line to the correct GPIO pin for the button.
* Set the trigger condition to the falling edge.
* NVIC Configuration:
* Enabled the NVIC interrupt line associated with the EXTI.
* Verified the interrupt priority is set correctly.
* Clock Setup:
* Enabled the clock for all required peripherals, including GPIO and SYSCFG.
* Issue:
* Despite all the configurations being correct, the NVIC pending register doesn’t reflect the button press when I check it. All other relevant registers seem to be correctly configured.
* Debugging Attempts:
* Cross checked every register.
* Physically checked the button’s connection and signal output. And also tried with internal button and internal led
* I’ve been stuck on this for days now and would really appreciate any insights or suggestions on what else I should check or do to resolve this issue.
13 Replies
Reference for those interested: https://www.youtube.com/watch?v=4C0tJ5Itnvo
DevHeads
YouTube
DevHeads Engineering Hour REHEAT: Interrupts and the NVIC Controlle...
Interrupts allow a processor to halt program execution to handle events such as state changes, which is essential for systems that rely on streaming sensor data inputs. They're also the foundation of any multi-tasking systems that does not use an operating system.
Learn how hardware interrupts work and how to implement an interrupt service rout...
Hi @techielew I have gone through his setup description.seems okay.
He may have created the function to setup and maybe forgot to call them .
I think we can help him well enough if we can get to see the code.
We must ask him to try the code from DevHeads Github repo. This external interrupt example project uses an onboard LED (PA5) and onboard Button switch (PC13) https://github.com/DevHeadsCommunity/EP-11-Explore-Interrupt-and-NVIC-Controller-in-Cortex-M-MCU/tree/main/EXTINT
GitHub
EP-11-Explore-Interrupt-and-NVIC-Controller-in-Cortex-M-MCU/EXTINT ...
Contribute to DevHeadsCommunity/EP-11-Explore-Interrupt-and-NVIC-Controller-in-Cortex-M-MCU development by creating an account on GitHub.
@Edison_ngunjiri @Umesh Lokhande , meet @lokii. He is the one with the referenced problem above. Here is his code: https://github.com/lokii2310/GPIO_INTERRUPT_DRIVER
GitHub
GitHub - lokii2310/GPIO_INTERRUPT_DRIVER
Contribute to lokii2310/GPIO_INTERRUPT_DRIVER development by creating an account on GitHub.
Hi, @lokii ,in the repository, I have seen 4 different .c files.
Which one you need help on?
The button_interrupt one
Hi @lokii, just checked your repo and
button_interrupt.c
file. I saw you've commented the entire while(1) loop. I mean line number 50...54
. You must keep the empty while loop even when you use interrupt. As you wrote GPIO drivers seperately stm32nul476rg_gpio_driver.h
Due to lack of time at my end to test for STM32L4. I suggest use my code (register level code) to do the necessory changes in your gpio driver file.Thank you so much for your time and help
But still it didn't turn out well actually. The led won't toggle yet.
In the file I had an error that
NVIC_EableIRQ(EXTI15_10_IRQn);
Is undefined
So added these lines instead of that
#define NVIC_BASE (0xE000E100UL)
#define NVIC_ISER1 (*(volatile uint32 *) (NVIC_BASE+0x004))
NVIC_ISER1 = (1<<(EXTI15_10_IRQn-32));
Still not led toggle
@lokii first try trouble shooting to make sure everything works and is on the right places then try this code
The code sets up the
LED
on GPIOC
pin 5 and configures an interrupt on GPIOC
pin 13, using HAL
functions to ensure proper setup of the NVIC
and EXTI
. The interrupt handler toggles the LED
and clears the interrupt flag when triggered.Actually trying to implement using my own driver files I have created. I'm not using hal drivers
I hope you have correctly mapped the EXTI line to the GPIO pin and that the NVIC configuration aligns with your EXTI settings. If everything is set up correctly, the NVIC pending register should reflect your button presses as expected
@lokii
`
This code actually works but here i have used the hal drivers
but when i try it with it the driver files i created it doesn't work