3151 views|6 replies

23

Posts

0

Resources
The OP
 

【ST NUCLEO-G071RB Review】_02_LED Light Experiment [Copy link]

This post was last edited by lvxinn2006 on 2019-1-11 08:53 [Purpose of the experiment]
  • Be familiar with how to analyze circuit principles through schematic diagrams;
  • Be familiar with how to use the user reference manual of the MCU;
  • Master the use of GPIO output functions through this experiment;
  • Begin to be familiar with the configuration method of the microcontroller registers;
  • Light up the LED with the least code.
[Experimental environment]
  • NUCLEO-G071RB development board
  • Keil MDK-ARM (Keil uVision 5.25.2.0)
  • Keil.STM32G0xx_DFP.1.0.0.pack
[Experimental materials]
  • NUCLEO-G071RB development board schematic diagram
  • STM32G071x8/xB Data Sheet
  • STM32G071 chip user reference manual
[Experimental phenomenon]
  • Light up LD4
[Schematic diagram analysis]
  • Open the schematic diagram and find the location of LD4;
  • Analysis principle, LD4 anode is connected to 3.3V positive voltage, cathode is connected to drain of N-channel field effect tube T2, source of field effect tube T2 is connected to power ground;
  • Conditions for lighting LD4: When the field effect tube is turned on, the cathode of LD4 is directly connected to the ground, generating current, and LD4 can be lit;
  • The gate of the field effect tube is pulled down to the ground through a 1M resistor. When a voltage difference is generated between Vds, the field effect tube can be turned on, that is, when the gate is connected to a high level (3.3V), Vds=-3.3V, the field effect tube can be turned on, and then LD4 can be lit.
  • As can be seen from the schematic diagram, the gate of the field effect tube is connected to the PA5 pin, so you only need to make PA5 output a high level to light up LD4.
  • Next, configure the PA5 pin according to the chip reference manual.
[MCU resource analysis and pin configuration]
  • Check the "STM32G071 Chip User Reference Manual", and you can see the following paragraph in the "Memory and Bus Structure" chapter:
According to the prompts in the paragraph, you can know that if you want to use the GPIO function unit, you must enable the corresponding clock. Here we can see that the RCC_IOPENR register can control the clock of the GPIO function, and we can know that the clock of GPIOA is at the [0] position of the register, and we only need to set the [0] position to 1
  • By looking at the Data Sheet of the STM32G071 chip, we can know that in this series of processors, there are 5 groups of GPIOs, namely PA, PB, PC, PD, and PF
  • For the 64-pin chips of the R series, there are up to 60 pins used as GPIOs
  • As can be seen in the figure above, each GPIO group has many pins. The available GPIOs of the 64-pin chip are PA0...PA15, PB0...PB15, PC0...PC15, PD0...PD9, PF0...1, a total of 60 pins
  • By consulting the data sheet, we can find out that each GPIO group in the chip corresponds to several registers with the same function. The specific functions of the registers are shown in the following table:
Register classificationSpecific registerFunction description
Configuration register
GPIOx_MODERSet input/output mode
GPIOx_OTYPERSet output type (push-pull, open-drain)
GPIOx_OSPEEDRSet output speed
GPIOx_PUPDRSet internal pull-up and pull-down resistors
Data register
GPIOx_IDRInput data
GPIOx_ODROutput data
Set reset register
GPIOx_BSRRSet, clear data
Lock register
GPIOx_LCKRLock pin data status
Multiplex function selection register
GPIOx_AFRHMultiplex function high data
GPIOx_AFRLMultiplex function low data
Each register has its own function. For the specific definition of registers, please refer to the chapter on GPIO in the "STM32G071 Chip User Reference Manual".
  • The principle of this experiment is relatively simple. Only two registers, MODER and ODR, are used, so we only study the use of these two registers
  • First look at GPIOx_MODER:

The MODER register is mainly used to set the function of each IO pin in a GPIO group. Every 2 data bits in the register determine the function of a pin, for example: [1:0] bits control the function of the PA0 pin, [3:2] bits control the function of the PA1 pin...

According to the needs of the experiment, we want to use PA5 to output a high level to control LD4, so we need to set the corresponding position of PA5, that is, [11:10] bits.

In the description, we can see that different combinations of two binary bits can determine the function of the pin. 00 indicates input mode, 01 indicates output mode, 10 indicates multiplexed function mode, and 11 is analog mode.

Because we want to use PA5 to output a level signal to control the circuit, we need to set PA5 to output mode, that is, set the two bits [11:10] to 01.

  • Let's take a look at GPIOx_ODR:

When the GPIO pin is set to output mode, the value of the corresponding data bit of the ODR register will determine the output level of the pin, 1 for high level, 0 for low level.

According to the experimental requirements, PA5 needs to output a high level, so it is necessary to set the [5] bit in the GPIOA_ODR register to 1.

[Analysis and Summary] All the above key points are organized into a mind map as follows: The next thing to do is to express these details in program code. 【Experimental code】
  • Open Keil and create a new project
Create a main.c file
  1. #include "stm32g0xx.h" // Device header int main(void) { //Enable GPIOA clock RCC->IOPENR |= (1<<0); //Set PA5 to output mode GPIOA->MODER &= ~(0x3<<10); //[11:10] clear 0 GPIOA->MODER |= (1<<10); //[11:10]=01 Set PA5 to output mode //Light up LD4 GPIOA->ODR |= (1<<5); //[5]=1 PA5 outputs high level}
复制代码
  • Compile the program
  • Set up the debugger
  • Burn the program
  • Press the reset button, run the program, and view the experimental results.
This content is created by EEWORLD forum user lvxinn2006. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source






图片4.png (49.3 KB, downloads: 0)

图片4.png
This post is from stm32/stm8

Latest reply

How to download the program on this board?  Details Published on 2019-3-14 11:42
 

931

Posts

3

Resources
2
 
Is this "STM32G071 Chip User Reference Manual" in Chinese? Can you share it?
This post is from stm32/stm8
 
 

11

Posts

0

Resources
3
 
I have learned it. Can you share the STM32 manual?
This post is from stm32/stm8
 
 

23

Posts

0

Resources
4
 
hujj posted on 2019-1-12 11:08 May I ask if this "STM32G071 Chip User Reference Manual" is in Chinese? Can you share it?
It's not in Chinese, it's in English

RM0444_STM32G0x1单片机参考手册.rar

7.39 MB, downloads: 13

This post is from stm32/stm8
 
 
 

23

Posts

0

Resources
5
 
Russel99 posted on 2019-1-14 20:45 I have learned it. Can you share the STM32 manual?
Shared

RM0444_STM32G0x1单片机参考手册.rar

7.39 MB, downloads: 1

This post is from stm32/stm8
 
 
 

931

Posts

3

Resources
6
 
Thank you! I have downloaded the English version from the official website, and I thought you had a Chinese version.
This post is from stm32/stm8
 
 
 

11

Posts

0

Resources
7
 
How to download the program on this board?
This post is from stm32/stm8
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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