Question: Hello, I need help finishing my code ( stm 3 2 controller = , c language ) . For the button inputs I am now
Hello, I need help finishing my code stm controller c language For the button inputs I am now using interrupts now and not sure if I use callback functions or how to finish the code, Here is what the code is whats supposed to happen in the code. Button Check Simple OnOff:
The code reads the state of a button Button
If the button is pressed logic an LED is turned on
If not, the LED is turned off.
Button Check Toggle on Falling Edge:
The state of the button is checked.
If pressed, the program toggles an LED based on the button press changes from high to low
It keeps the LED state until the button is released.
Button Check Toggle on Rising Edge:
Similar to Button but it toggles the LED when the button changes from low to high.
Button Check Double Click Toggle:
This part implements a simple doubleclick detection mechanism.
The code increments a counter each time the button is pressed.
If the button is pressed twice quickly, the LED toggles its state
AND MY CODE BELOW:
int mainvoid
USER CODE BEGIN
USER CODE END
MCU Configuration
Reset of all peripherals, Initializes the Flash interface and the Systick.
HALInit;
USER CODE BEGIN Init
USER CODE END Init
Configure the system clock
SystemClockConfig;
USER CODE BEGIN SysInit
USER CODE END SysInit
Initialize all configured peripherals
MXGPIOInit;
MXUSARTUARTInit;
USER CODE BEGIN
USER CODE END
Infinite loop
USER CODE BEGIN WHILE
while
USER CODE END WHILE
USER CODE BEGIN
USER CODE END
@brief System Clock Configuration
@retval None
void SystemClockConfigvoid
RCCOscInitTypeDef RCCOscInitStruct ;
RCCClkInitTypeDef RCCClkInitStruct ;
Configure the main internal regulator output voltage
HALRCCPWRCLKENABLE;
HALPWRVOLTAGESCALINGCONFIGPWRREGULATORVOLTAGESCALE;
Initializes the RCC Oscillators according to the specified parameters
in the RCCOscInitTypeDef structure.
RCCOscInitStruct.OscillatorType RCCOSCILLATORTYPEHSI;
RCCOscInitStruct.HSIState RCCHSION;
RCCOscInitStruct.HSICalibrationValue RCCHSICALIBRATIONDEFAULT;
RCCOscInitStruct.PLLPLLState RCCPLLON;
RCCOscInitStruct.PLLPLLSource RCCPLLSOURCEHSI;
RCCOscInitStruct.PLLPLLM ;
RCCOscInitStruct.PLLPLLN ;
RCCOscInitStruct.PLLPLLP RCCPLLPDIV;
RCCOscInitStruct.PLLPLLQ ;
RCCOscInitStruct.PLLPLLR ;
if HALRCCOscConfig&RCCOscInitStruct HALOK
ErrorHandler;
Initializes the CPU, AHB and APB buses clocks
RCCClkInitStruct.ClockType RCCCLOCKTYPEHCLKRCCCLOCKTYPESYSCLK
RCCCLOCKTYPEPCLKRCCCLOCKTYPEPCLK;
RCCClkInitStruct.SYSCLKSource RCCSYSCLKSOURCEPLLCLK;
RCCClkInitStruct.AHBCLKDivider RCCSYSCLKDIV;
RCCClkInitStruct.APBCLKDivider RCCHCLKDIV;
RCCClkInitStruct.APBCLKDivider RCCHCLKDIV;
if HALRCCClockConfig&RCCClkInitStruct, FLASHLATENCY HALOK
ErrorHandler;
@brief USART Initialization Function
@param None
@retval None
static void MXUSARTUARTInitvoid
USER CODE BEGIN USARTInit
USER CODE END USARTInit
USER CODE BEGIN USARTInit
USER CODE END USARTInit
huartInstance USART;
huartInit.BaudRate ;
huartInit.WordLength UARTWORDLENGTHB;
huartInit.StopBits UARTSTOPBITS;
huartInit.Parity UARTPARITYNONE;
huartInit.Mode UARTMODETXRX;
huartInit.HwFlowCtl UARTHWCONTROLNONE;
huartInit.OverSampling UARTOVERSAMPLING;
if HALUARTInit&huart HALOK
ErrorHandler;
USER CODE BEGIN USARTInit
USER CODE END USARTInit
@brief GPIO Initialization Function
@param None
@retval None
static void MXGPIOInitvoid
GPIOInitTypeDef GPIOInitStruct ;
USER CODE BEGIN MXGPIOInit
USER CODE END MXGPIOInit
GPIO Ports Clock Enable
HALRCCGPIOCCLKENABLE;
HALRCCGPIOHCLKENABLE;
HALRCCGPIOACLKENABLE;
HALRCCGPIOBCLKENABLE;
Configure GPIO pin Output Level
HALGPIOWritePinGPIOA GPIOPINGPIOPINGPIOPIN GPIOPINRESET;
Configure GPIO pin Output Level
HALGPIOWritePinGPIOB GPIOPIN GPIOPINRESET;
Configure GPIO pins : PC PC PC
GPIOInitStruct.Pin GPIOPINGPIOPINGPIOPIN;
GPIOInitStruct.Mode GPIOMODEITFALLING;
GPIOInitStruct.Pull GPIOPULLUP;
H
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
