Issues with GPIO Configuration and Button Functionality on STM32

So guys, In my setup, I’ve configured the GPIO pins as follows:
RCC->AHBENR |= RCC_AHBENR_GPIOAEN; // Enable the bus for port IOPA.

GPIOA->MODER |= 0x400; // Set MODER5 (PA5) for LD2,
GPIOA->MODER |= 0x100000; // Set MODER10 (PA10) for LED

GPIOC->PUPDR |= 0x2000000; // Configure PC13 for B1
GPIOA->PUPDR |= 0x20; // Configure PA2 for B2
RCC->AHBENR |= RCC_AHBENR_GPIOAEN; // Enable the bus for port IOPA.

GPIOA->MODER |= 0x400; // Set MODER5 (PA5) for LD2,
GPIOA->MODER |= 0x100000; // Set MODER10 (PA10) for LED

GPIOC->PUPDR |= 0x2000000; // Configure PC13 for B1
GPIOA->PUPDR |= 0x20; // Configure PA2 for B2
In the main loop:
while (1)
{
if(GPIOA->IDR |= 0x4){
GPIOA->BSRR = 0x400;
HAL_Delay(1000);
GPIOA->BRR = 0x400;
HAL_Delay(1000);
}

if(GPIOC->IDR &= 0x2000){
GPIOA->BRR = 0x20;
}
else{
GPIOA->BSRR = 0x20;
}
}
while (1)
{
if(GPIOA->IDR |= 0x4){
GPIOA->BSRR = 0x400;
HAL_Delay(1000);
GPIOA->BRR = 0x400;
HAL_Delay(1000);
}

if(GPIOC->IDR &= 0x2000){
GPIOA->BRR = 0x20;
}
else{
GPIOA->BSRR = 0x20;
}
}
The LED is being toggled solely by the initial if statement, and there appears to be no response from the button. The second if statement is accurate but needs to operate in parallel similar to how millis() works within the Arduino IDE. I have some questions: + Have I overlooked any configurations for the button and what steps shall I take to make it function? + What steps do I need to take in order for it to work simultaneously?
9 Replies
ZacckOsiemo
ZacckOsiemo3mo ago
ok I'll bite , what are you attempting
te0
te03mo ago
How are you handling debouncing in this?
Sterling
Sterling3mo ago
Oh, should have been more elaborate earlier 🙏🏽
Sterling
Sterling3mo ago
I am trying to focus on working on a Dual-function button controlled LED system where two LEDs are controlled by different buttons with one being toggled on & off when it's button is pressed whilst the other LED responding to its own button in real-time while both LEDs operate concurrently @ZacckOsiemo
ZacckOsiemo
ZacckOsiemo3mo ago
ok so concurrently means managing multiple tasks at once, not necessarily running at the same time. Is that what you mean or do you mean both running at the same time?
Sterling
Sterling3mo ago
running at the same time
ZacckOsiemo
ZacckOsiemo3mo ago
then you need more than one core
ZacckOsiemo
ZacckOsiemo3mo ago
physics, kinda dictates that
Edison_ngunjiri
Edison_ngunjiri3mo ago
Hi,Enable clock to port C. RCC_AHB1ENR_GPIOCEN
Want results from more Discord servers?
Add your server