If the paper is original articles, reprint please indicate the original source This article blog: blog.csdn.net/qq21497936/…
Development technology set (including Qt practical technology, raspberry PI, 3D, OpenCV, OpenGL, FFMPEG, OSG, SCM, soft and hard combination, etc.) continue to update… (Click on the portal)
SCM related development
The stM32 series uses V3.5 firmware library help files and GPIO basic functions.
preface
Stm32 series is one of the most commonly used microcontroller, different versions of the corresponding pins, peripherals, frequency, capacity, etc. ‘in addition to the different, its development method is the same. This chapter explains how to use THE GPIO pin function to drive LED lights and receive Key button input.
STM32 series GPIO driver LED lamp
First, the author uses GPIO for LED operation according to the circuit of the development board he uses. The following figure is the circuit diagram of the LED lamp of the development board he uses:Pin PD6 is connected to LED1, PD12 is connected to LED2, PD13 is connected to LED3, and the resistor is the current limiting resistor (calculate mode high level minus the voltage drop of LED1, and then divide by the current that LED can flow). Copy the template file, change the name to LEDtest1, start the software Keil4, and open the renamed project LEDtest1. Create a new folder Dev under the project directory, create a new folder LED under Dev, create led.c and led.h files under LED, and then deploy the path and files in it: After successful deployment, our project is as follows:C, LEd.c, leD.h. The content of the program is as follows: The main logic of the program is as follows: Open LED1, delay, open LED2, delay, open LED3, delay, close LED1 LED2 LED3, delay, turn back the cycle begins.
The engineering code of LED can be downloaded at CSDN
CSDN download address: download.csdn.net/detail/qq21… QQ group free download: 1047134658 (click “file” search “LEDtest1”, group and blog post update synchronously)
STM32 Series GPIO detection KEY
Now we are going to use GPIO for key operation. The most common input of key is polling (query), which is recommended by most of the experienced people I have contacted. The following is the circuit diagram of the key part of the author’s development board:According to the circuit diagram, the five pins PE0, PE1, PE2, PE3 and PE4 are high level with pull-up resistance when they are not pressed. When pressed, there are two 10K resistors for voltage division, which is 1.65V. Check the electrical characteristics of chip level, you will find that the lowest voltage is lower than high level. PC13 only has pull-up resistance. As for the reason of this, I am not clear at the moment, so we copy LEDtest1 project, rename it KEYtest1, and then continue to write keys. We still follow the process, create KEY folder under Dev folder, and create key.h under KEY folder. Key. c both files are deployed into the project and paths are included. Continue to use the help documentation for reference. The version is V3.5 (or if V3.4 is not specified, it is recommended that both versions be ready when using the documentation). Open the source file below
LEDtest1 GPIO is configured as output, so the key should be configured as input, which input (you can refer to the eight IO modes), here we consider for beginners, try to only rely on the help document, so we continue to use the help document to write, configured as input also has an initialization, So in the source code, we look at the following figureLine 00067 initializes the button, and we click this function to jump to the source codeClick 255 again to see the source code00257 as you all know, 00258 is to configure the details of the interrupt (how to generate the interrupt), 00259 is to associate the interrupt with the interrupt vector (you can configure the priority and the interrupt response function), we don’t use the interrupt regardless of the next two lines of the interrupt, continue down, okayThis is configured as floating input, we think this is what we want (right or wrong, for now), keep goingThe bit 00316 reads the input data and we click on it to go to its descriptionThe value of the input pin is either 0 or 1, and the code can be written as follows: The debugging succeeded. Procedure In addition, the author has configured pull-up, pull-down and floating input in GPIO mode, which all work normally, including UESR button.
KEY engineering code download
CSDN download address: download.csdn.net/detail/qq21… QQ group free download: 1047134658 (click “file” search “KEYtest1”, group and blog post synchronous update)
The stM32 series uses V3.5 firmware library help files and GPIO basic functions.
If the paper is original articles, reprint please indicate the original source This article blog: blog.csdn.net/qq21497936/…