Question: Hello I have this code from a stm 3 2 controller in c code, that Im trying to change the button inputs, now into interupts

Hello I have this code from a stm32 controller in c code, that Im trying to change the button inputs, now into interupts for my code. I'll paste my code below (The LED pins stay the same(.
#include "main.h"
#include
UART_HandleTypeDef huart2;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
int main(void)
{
int count =0;
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
while (1)
{
/*Button 0*/
if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)==0)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4,1);
}
else
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4,0);
}
/*Button 1- Falling Edge Toggling Cycle*/
if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_4)==0)
{
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_5)==1)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,0);
}
else
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,1);
}
while(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_4)==0)
{}
}
/*Button 2- Rising Edge Toggling Cycle*/
if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_5)==0)
{
while(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_5)==0)
{}
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_6)==1)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,0);
}
else
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
}
}
/*Button 3 Double Click Falling Edge Toggling Cycle*/
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_12)==0)
{
while(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_12)==0)
{}
if(count ==1)
{
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1)==1)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,0);
}
else
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,1);
}
count =0;
}
else
{
count = count +1;
}
}
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct ={0};
RCC_ClkInitTypeDef RCC_ClkInitStruct ={0};
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM =16;
RCC_OscInitStruct.PLL.PLLN =336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ =2;
RCC_OscInitStruct.PLL.PLLR =2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
{
Error_Handler();
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2)!= HAL_OK)
{
Error_Handler();
}
}
static void MX_USART2_UART_Init(void)
{
huart2.Instance = USART2;
huart2.Init.BaudRate =115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2)!= HAL_OK)
{
Error_Handler();
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct ={0};
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_4|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void Error_Handler(void)
{
__disable_irq();
while (1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!