Button push not changing LED status
I am working with the NUCLEO-C031C6 board and tried to to make the user push button toggle the user LED but it stays stuck with no change to the buttonStatus variable, always high (1).
I added the counter variable to see if it is continuously incrementing, however, it appears that the code does not loop and gets stuck somewhere, and thus when I press the push button, it is not updating the buttonStatus variable.
Can you please see where the issue is:
#include "stm32c0xx_hal.h"
//Blue button = PC13, BUS AHB1 EN bit 0
#define BLUBTN_Port GPIOC
#define BLUBTN_Pin GPIO_PIN_13
//Green LED = PA5, BUS AHB1 EN bit 2
#define GRNLED_Port GPIOA
#define GRNLED_Pin GPIO_PIN_5
void PA5_LED_init(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GRNLED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GRNLED_Port, &GPIO_InitStruct);
}
void PC13_BLUBTN_init(void)
{
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = BLUBTN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(BLUBTN_Port, &GPIO_InitStruct);
}
void Systick_Handler (void)
{
HAL_IncTick();
}
uint8_t buttonStatus;
int counter;
int main()
{
HAL_Init();
PA5_LED_init();
PC13_BLUBTN_init();
while(1)
{
buttonStatus = HAL_GPIO_ReadPin(BLUBTN_Port, BLUBTN_Pin);
HAL_GPIO_WritePin(GRNLED_Port, GRNLED_Pin, buttonStatus);
counter++;
/*if (buttonStatus == 0)
{
//HAL_GPIO_WritePin(GRNLED_Port, GRNLED_Pin, GPIO_PIN_SET);
HAL_GPIO_TogglePin(GRNLED_Port, GRNLED_Pin);
HAL_Delay(200);
}*/
}
}I suspect it has something to do with the clock / systick handler but not sure how to resolve this.
