3223 views|7 replies

821

Posts

0

Resources
The OP
 

【ST NUCLEO-G071RB Review】GPIO [Copy link]

This post was last edited by lising on 2019-1-6 14:15 The NUCLEO-G071RB development board used in this experiment is provided by https://www.stmcu.com.cn/index.p ... /261/layout/product . For more relevant information, please go to the query. This experiment includes two contents: one is to use the query method to detect the "USER" button and control the on and off of LD4; the other is to use the interrupt method. 1. Experimental resources 1. NUCLEO-G071RB development board; 2. Keil v5.25.2.0; 3. Keil.STM32G0xx_DFP.1.0.0; 4. STM32CubeMX v5.0.1; 5. stm32cube_fw_g0_v100; 2. Experimental process 1. Software installation. I won’t talk about the specific installation process of the above software. Keil and STM32CubeMX have been installed before. Since the microcontroller STM32G071RBT6 used in the NUCLEO-G071RB development board is a new generation of products from ST, Keil.STM32G0xx_DFP.1.0.0 and stm32cube_fw_g0_v100 must be installed before using Keil and STM32CubeMX. These two plug-ins can be installed directly in the application software or downloaded and installed. The final result is as shown below: 2. The first experiment - use the query method to detect the state of the user button (blue) "USER" and control the on and off of LD4. From the schematic diagram, it can be seen that "USER" is connected to PC13 through an external pull-up resistor. When the button is pressed and a low level is detected in PC13, LD4 is lit, otherwise LD4 is extinguished; LD4 is controlled by an N-MOS and the PA5 pin. When PA5 outputs a high level, the N-MOS is turned on and LD4 is lit, otherwise LD4 is extinguished; 3. Program implementation The main body of the program is generated by STM32CubeMX, which is convenient, fast and efficient. Here PA5 is configured as output mode, and the initial output is low level; PC13 is configured as input; the clock uses HSE. After processing these and simple settings, the code can be generated. When the generated project file is opened by Keil, you will find that the port and clock have been configured. You don’t need to pay attention to them anymore. You just need to implement the target function in the main function. The following is the function code:
  1. /* USER CODE BEGIN WHILE */ while (1) { if(!HAL_GPIO_ReadPin(USER_KEY_GPIO_Port, USER_KEY_Pin)) { HAL_Delay(20); if(!HAL_GPIO_ReadPin(USER_KEY_GPIO_Port, USER_KEY_Pin)) { HAL_GPIO_WritePin(LD4_GPIO _Port, LD4_Pin, GPIO_PIN_SET); while(!HAL_GPIO_ReadPin(USER_KEY_GPIO_Port, USER_KEY_Pin)); key_cont++; if(key_cont==2) { key_cont=0; HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_RESET); } } } /* USER CODE END WHILE */
复制代码
4. The second experiment - the interrupt method detects the button status and controls the on and off of LD4. The interrupt function can save a lot of valuable resources and respond quickly. In fact, the user button (PC13) itself has the "GPIO_EXTI13" external interrupt function. This experiment uses its function of generating an interrupt on the falling edge. 5. Program implementation The following is the main code for the function implementation. Some comments have been added to the function according to my understanding. If there are errors caused by my ability level, please give me advice. a. Interrupt configuration function, which is initialized in the main function.
  1. /*External interrupt configuration*/ void EXTI4_15_IRQHandler_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; /*Enable GPIOC clock*/ __HAL_RCC_GPIOC_CLK_ENABLE(); /* Falling edge external interrupt; No pull-up or pull-down; Set PC13 pin; Complete pin configuration; */ GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Pin = USER_KEY_Pin; HAL_GPIO_Init(USER_KEY_GPIO_Port, &GPIO_InitStructure); /* User key connected to PC13 port, that is, external interrupt "EXTI Line 4 to 15 Interrupts"; Set interrupt priority (0~3), here set to the highest "0"; The M0+ core does not support interrupt sub-priority, so it is set to "0" here; */ HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0,0); /* Enable PC13 pin interrupt */ HAL_NVIC_EnableIRQ(EXTI4_15_IRQn); }
复制代码
b. Interrupt handling function, which is ready to work at any time in stm32g0xx_it.c;
  1. /* USER CODE BEGIN 1 */ void EXTI4_15_IRQHandler(void) { HAL_GPIO_EXTI_IRQHandler(USER_KEY_Pin); } /* USER CODE END 1 */
复制代码
c. After the interrupt is generated, HAL_GPIO_EXTI_IRQHandler(USER_KEY_Pin) will call the HAL_GPIO_EXTI_Falling_Callback(GPIO_Pin) function, which is defined as a "weak function" (__weak void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)), when the function is rewritten, the newly written one will be called in, and the "weak function" will be ignored. The called function is also called the "callback function";
  1. /*PC13 pin interrupt callback function, called by the interrupt processing function EXTI4_15_IRQHandler()*/ void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == USER_KEY_Pin)//Confirm that PC13 generates a falling edge pulse { HAL_GPIO_TogglePin(LD4_GPIO_Port, LD4_Pin);//LD4 port flips } }
复制代码
3. Experimental results The results of the two experiments are as described above. 4. Experimental summary Through the study of the two small experimental processes, the NUCLEO-G071RB development board and STM32G071RBT6 microcontroller have gained some new understanding and knowledge. Next, we will do more experiments to learn. Some of the descriptions in this article may have some problems, so please give me some advice. RM0444_STM32G0x1单片机参考手册.rar (7.39 MB, downloads: 15) This content was originally created by EEWORLD forum user lising. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source


This post is from stm32/stm8

Latest reply

Isn't the crystal oscillator on the schematic a 32.768K one?  Details Published on 2024-10-9 16:40
 

931

Posts

3

Resources
2
 
Thank you for sharing. It is a good opportunity for me to learn from it and avoid taking detours.
This post is from stm32/stm8

Comments

Learn from each other and make progress together  Details Published on 2019-1-7 22:11
 
 

821

Posts

0

Resources
3
 
hujj posted on 2019-1-7 22:00 Thank you for sharing, it is just right for me to learn from and avoid detours.
Learn from each other and make progress together: handshake
This post is from stm32/stm8
 
 

931

Posts

3

Resources
4
 
I followed the instructions in your post and downloaded and upgraded Keil.STM32G0xx.DFP.1.0.0, but I couldn't find the file stm32cube_fw_g0_v100. Where can I download this file? What does it do? Thank you!
This post is from stm32/stm8
 
 
 

821

Posts

0

Resources
5
 
stm32cube_fw_g0_v100 is a plug-in for STM32CubeMX to support the STM32G0 series. With its support, STM32CubeMX can be configured to generate the project files for NUCLEO-G071RB. You can download it from ST Chinese or ST official website or install it directly in STM32CubeMX.
This post is from stm32/stm8
 
 
 

931

Posts

3

Resources
6
 
Thanks for the advice! I have downloaded and installed the STM32CubeMX software and am learning how to use it.
This post is from stm32/stm8

Comments

The STM32CubeMX software is very easy to use, especially the clock configuration is very worry-free.  Details Published on 2019-1-8 19:54
 
 
 

821

Posts

0

Resources
7
 
hujj posted on 2019-1-8 15:33 Thank you for your advice! I have downloaded and installed the STM32CubeMX software and am learning how to use it.
The STM32CubeMX software is very easy to use, especially the configuration of the clock is very worry-free.
This post is from stm32/stm8
 
 
 

21

Posts

0

Resources
8
 
Isn't the crystal oscillator on the schematic a 32.768K one?
This post is from stm32/stm8
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list