当前位置:网站首页>Bearpi IOT lighting LED

Bearpi IOT lighting LED

2022-06-12 04:27:00 Learn the Mediterranean

STM32CubeMX Lighten up LED The lamp

1、 Schematic diagram

Chip type : STM32L431RC
LED Pin : PC13
Output mode : Push pull output , Output high level is on LED The lamp
 Insert picture description here

 Insert picture description here

2、STM32CubeMX To configure LED

Be careful : The project save path cannot contain Chinese characters , otherwise KEIL5 The boot file will not be found , The following error occurred
 Insert picture description here

1、 Create a new project

 Insert picture description here
2、 Select chip , Double click in
 Insert picture description here
3、 Configure pins
 Insert picture description here
After selecting the pin , Set user alias , Easy to program
 Insert picture description here
4、 Configure clock tree
 Insert picture description here
5、 Build project
Here, I accidentally saved the file in the Chinese path , Has been changed ! Do not commit !!!
 Insert picture description here
 Insert picture description here

2、 Write code

Be careful : The user code needs to be written in
/* USER CODE BEGIN */

/* USER CODE END * / Between , Otherwise, if you reuse CubeMX Generate the file code , User codes outside these areas will be deleted

1、 The correlation function is in stm32l4xx_hal_gpio.h Statement in , You can use the following function to achieve LED Pin output of
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
For example, the following writing , Can achieve 1sLED State flip :
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);// destroy
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);// bright
HAL_Delay(1000);
perhaps
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);// Flip
HAL_Delay(1000);
 Insert picture description here

3、 Burn files

1、 install STLINK drive
2、 Set the burning mode
 Insert picture description here
3、 Compile and download
 Insert picture description here

原网站

版权声明
本文为[Learn the Mediterranean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010951046491.html