lokii
DIIDevHeads IoT Integration Server
•Created by techielew on 9/9/2024 in #firmware-and-baremetal
Need Help with NVIC Pending Register Not Reflecting Button Press on STM32L476RG
17 replies
DIIDevHeads IoT Integration Server
•Created by techielew on 9/9/2024 in #firmware-and-baremetal
Need Help with NVIC Pending Register Not Reflecting Button Press on STM32L476RG
void GPIO_IRQPriorityConfig(uint8_t IRQNumber, uint32_t IRQPriority)
{
//1. First find the ipr register
uint8_t iprx = IRQNumber/4;
uint8_t iprx_section = IRQNumber%4;
uint8_t shift_amount = (8 * iprx_section) + (8 - NO_PR_BITS_IMPLEMENTED);
*(NVIC_PR_BASE_ADDR + iprx ) |= ( IRQPriority << shift_amount);
}
void GPIO_IRQInterruptConfig(uint8_t IRQNumber, uint8_t EnorDi)
{
if(EnorDi == ENABLE)
{
if(IRQNumber <=31)
{
// program ISER0 register
*NVIC_ISER0 |= (1<< IRQNumber);
}
else if(IRQNumber >31 && IRQNumber<64 )
{
// program ISER1 register
*NVIC_ISER1 |= (1<< IRQNumber%32);
}
else if(IRQNumber>= 64 && IRQNumber<96)
{
// program ISER2 register
*NVIC_ISER2 |= (1<< IRQNumber%64);
}
}
else
{
if(IRQNumber <=31)
{
// program ICER0 register
*NVIC_ICER0 |= (1<< IRQNumber);
}
else if(IRQNumber >31 && IRQNumber<64 )
{
// program ICER1 register
*NVIC_ICER1 |= (1<< IRQNumber%32);
}
else if(IRQNumber>= 64 && IRQNumber<96)
{
// program ICER2 register
*NVIC_ICER2 |= (1<< IRQNumber%64);
}
}
}
void GPIO_IRQPriorityConfig(uint8_t IRQNumber, uint32_t IRQPriority)
{
//1. First find the ipr register
uint8_t iprx = IRQNumber/4;
uint8_t iprx_section = IRQNumber%4;
uint8_t shift_amount = (8 * iprx_section) + (8 - NO_PR_BITS_IMPLEMENTED);
*(NVIC_PR_BASE_ADDR + iprx ) |= ( IRQPriority << shift_amount);
}
void GPIO_IRQInterruptConfig(uint8_t IRQNumber, uint8_t EnorDi)
{
if(EnorDi == ENABLE)
{
if(IRQNumber <=31)
{
// program ISER0 register
*NVIC_ISER0 |= (1<< IRQNumber);
}
else if(IRQNumber >31 && IRQNumber<64 )
{
// program ISER1 register
*NVIC_ISER1 |= (1<< IRQNumber%32);
}
else if(IRQNumber>= 64 && IRQNumber<96)
{
// program ISER2 register
*NVIC_ISER2 |= (1<< IRQNumber%64);
}
}
else
{
if(IRQNumber <=31)
{
// program ICER0 register
*NVIC_ICER0 |= (1<< IRQNumber);
}
else if(IRQNumber >31 && IRQNumber<64 )
{
// program ICER1 register
*NVIC_ICER1 |= (1<< IRQNumber%32);
}
else if(IRQNumber>= 64 && IRQNumber<96)
{
// program ICER2 register
*NVIC_ICER2 |= (1<< IRQNumber%64);
}
}
}
17 replies
DIIDevHeads IoT Integration Server
•Created by techielew on 9/9/2024 in #firmware-and-baremetal
Need Help with NVIC Pending Register Not Reflecting Button Press on STM32L476RG
but when i try it with it the driver files i created it doesn't work
#include "stm32nul476rg.h"
#include "string.h"
void delay(void)
{
for(uint32_t i = 0; i < 50000/2; i++);
}
#define LOW 1
#define BTN_PRESSED LOW
int main(void)
{
GPIO_Handle_t GpioLed, GpioBtn;
memset(&GpioLed, 0, sizeof(GpioLed));
memset(&GpioBtn, 0, sizeof(GpioBtn));
// LED GPIO configuration
GpioLed.pGPIOx = GPIOA;
GpioLed.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_5;
GpioLed.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_OUT;
GpioLed.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_LOW;
// GpioLed.GPIO_PinConfig.GPIO_PinOPType = GPIO_OP_TYPE_PP;
GpioLed.GPIO_PinConfig.GPIO_PinPuPdContol = GPIO_NO_PUPD;
// GPIO_PeriClockControl(GPIOA, ENABLE);
GPIO_Init(&GpioLed);
// Button GPIO configuration
GpioBtn.pGPIOx = GPIOC;
GpioBtn.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_13;
GpioBtn.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_IT_FT; // Interrupt mode, falling edge
// GpioBtn.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_FAST;
GpioBtn.GPIO_PinConfig.GPIO_PinPuPdContol = GPIO_NO_PUPD;
// GPIO_PeriClockControl(GPIOC, ENABLE);
GPIO_Init(&GpioBtn);
// IRQ configuration
GPIO_IRQPriorityConfig(IRQ_NO_EXTI15_10, NVIC_IRQ_PRI15);
GPIO_IRQInterruptConfig(IRQ_NO_EXTI15_10, ENABLE);
while(1);
// while(1){
// delay();
// GPIO_ToggleOutputPin(GPIOA, GPIO_PIN_NO_5); // Toggle the LED
//
// }
return 0;
}
void EXTI15_10_IRQHandler(void)
{
if(GPIO_ReadFromInputPin(GPIOC, 13) != BTN_PRESSED)
{
GPIO_IRQHandling(GPIO_PIN_NO_13); // Clear the interrupt flag
GPIO_ToggleOutputPin(GPIOA, GPIO_PIN_NO_5); // Toggle the LED
}
}
#include "stm32nul476rg.h"
#include "string.h"
void delay(void)
{
for(uint32_t i = 0; i < 50000/2; i++);
}
#define LOW 1
#define BTN_PRESSED LOW
int main(void)
{
GPIO_Handle_t GpioLed, GpioBtn;
memset(&GpioLed, 0, sizeof(GpioLed));
memset(&GpioBtn, 0, sizeof(GpioBtn));
// LED GPIO configuration
GpioLed.pGPIOx = GPIOA;
GpioLed.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_5;
GpioLed.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_OUT;
GpioLed.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_LOW;
// GpioLed.GPIO_PinConfig.GPIO_PinOPType = GPIO_OP_TYPE_PP;
GpioLed.GPIO_PinConfig.GPIO_PinPuPdContol = GPIO_NO_PUPD;
// GPIO_PeriClockControl(GPIOA, ENABLE);
GPIO_Init(&GpioLed);
// Button GPIO configuration
GpioBtn.pGPIOx = GPIOC;
GpioBtn.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_13;
GpioBtn.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_IT_FT; // Interrupt mode, falling edge
// GpioBtn.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_FAST;
GpioBtn.GPIO_PinConfig.GPIO_PinPuPdContol = GPIO_NO_PUPD;
// GPIO_PeriClockControl(GPIOC, ENABLE);
GPIO_Init(&GpioBtn);
// IRQ configuration
GPIO_IRQPriorityConfig(IRQ_NO_EXTI15_10, NVIC_IRQ_PRI15);
GPIO_IRQInterruptConfig(IRQ_NO_EXTI15_10, ENABLE);
while(1);
// while(1){
// delay();
// GPIO_ToggleOutputPin(GPIOA, GPIO_PIN_NO_5); // Toggle the LED
//
// }
return 0;
}
void EXTI15_10_IRQHandler(void)
{
if(GPIO_ReadFromInputPin(GPIOC, 13) != BTN_PRESSED)
{
GPIO_IRQHandling(GPIO_PIN_NO_13); // Clear the interrupt flag
GPIO_ToggleOutputPin(GPIOA, GPIO_PIN_NO_5); // Toggle the LED
}
}
17 replies
DIIDevHeads IoT Integration Server
•Created by techielew on 9/9/2024 in #firmware-and-baremetal
Need Help with NVIC Pending Register Not Reflecting Button Press on STM32L476RG
#include "stm32l4xx.h"
void EXTI15_10_IRQHandler(void) {
// Check if EXTI line 13 triggered the interrupt
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_13) != RESET) {
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_13); // Clear the interrupt flag
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); // Toggle the LED pin
}
}
int main(void) {
HAL_Init();
// Enable the GPIOC clock for the LED
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
// Configure LED pin (PA5) as output
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// Enable the SYSCFG clock for EXTI
__HAL_RCC_SYSCFG_CLK_ENABLE();
// Configure button pin (PC13) as input with EXTI
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
// Set priority and enable EXTI line 15-10 interrupt in NVIC
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
while (1) {
// Main loop
}
}
#include "stm32l4xx.h"
void EXTI15_10_IRQHandler(void) {
// Check if EXTI line 13 triggered the interrupt
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_13) != RESET) {
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_13); // Clear the interrupt flag
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); // Toggle the LED pin
}
}
int main(void) {
HAL_Init();
// Enable the GPIOC clock for the LED
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
// Configure LED pin (PA5) as output
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// Enable the SYSCFG clock for EXTI
__HAL_RCC_SYSCFG_CLK_ENABLE();
// Configure button pin (PC13) as input with EXTI
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
// Set priority and enable EXTI line 15-10 interrupt in NVIC
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
while (1) {
// Main loop
}
}
17 replies