我使用的是 stm32g030f6 微控制器,我想每 1 秒切换一次 LED。
这是我的代码
#include "main.h"
uint8_t cnt = 0;
bool send = false;
HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
cnt++;
if (cnt >= 25)
{
cnt = 0;
send = true;
}
}
int main()
{
MX_GPIO_Init();
MX_TIM1_Init();
HAL_TIM_Base_Start_IT(&htim1);
while(1)
{
if(send == true)
{
send = false;
HAL_GPIO_TOGGLE(GPIOA, GPIO_PIN_2);
}
}
}
时钟频率为 16 MHz,定时器预分频器值为 15,ARR 值为 39999。
但是程序永远不会进入 while(1) 循环。我该怎么办
在设置中关闭所有编译器优化后,我的问题解决了