GPIO has various functions, such as driving LED lights, obtaining key input information...
To drive LED lights, you need to configure GPIO as above.
Basic knowledge:
April 24, 2013:
Afternoon:
Reasons for learning stm32:
1. From the kernel: When most people start learning, they all start with arm7, but since the appearance of the stm32 development board, it has been found that people are
using stm32 more.
2. From the purpose: stm32 microcontrollers are widely used in industrial control, consumer electronics, handheld devices, automotive electronics, security monitoring and many other fields
, and their high cost performance is suitable for manual DIY.
Comparison between arm7 and stm32:
Cortex-32 is one-third faster than arm7, one-quarter less power, and can achieve a smaller chip area, which is conducive to integrating more functions into a smaller
chip size. The cortex-m3 processor combines a 32-bit Harvard microarchitecture that executes Thumb-2 instructions and system peripherals, including Nested Vectored Interrupt
Controller and Arbiter bus.
In the field of industrial control, users require faster interrupt speeds. The cortex-m3 uses Tail-Chaining interrupt technology, which is completely based on hardware interrupt processing,
which can reduce up to 12 clock cycles. In actual applications, it can reduce the number of interrupts by 70%.
Learn about AVR:
AVR can be said to be a very successful chip with low power consumption and strong performance. Compared with the previous 51, the performance has been improved by several levels. AVR has a rich peripherals that
can meet the general projects.
However, since the emergence of STM32, AVR has "retired from the arena".
Because it is incomparable with stm32.
3. Easy to use:
1. Support serial port download
2. All IO ports can generate interrupts
3. More technical information
4. Support SWD download
5. Multiplex IO port remapping function
Note:
Compilation software:
1. MDK or IAR?
Generally, MDK is used
2. Firmware library or register?
Generally, both must be used and learned.
IAR's compilation code speed, flash usage, etc. are better than MDK, but they are not very large.
But IAR is generally not used,
but:
Keil (acquired by ARM):
1. User-friendly interface
2. Simple configuration
3. Simple operation
STM32 minimum system (a system that can make the microcontroller work):
1. Power
2. Reset
3. Clock
4. Download circuit (many people think this does not belong to the minimum system, but it is still added to be complete)
The main thing to pay attention to is the clock.
Pay attention to the clock distribution, source, and several ways out.
1. Initialization function of the system clock.
2. Implementation of the delay function.
Software delay is a relatively simple method, which uses the CPU to execute a loop statement to produce a delay effect.
For stm32, it only takes a few dozen nanoseconds to execute an instruction. For a for loop, the x value to achieve N milliseconds is very large, and due to the
wide frequency of the system, it is difficult to calculate the exact value of the delay of N milliseconds.
Software delay does not occupy timer resources, but it occupies CPU resources. Its delay accuracy is not high, and it is suitable for applications where the delay accuracy is not high. It is
very important to note that:
A very important aspect of GPIO configuration is the provision of clock. Without clock, even if everything is configured well, it will be in vain.
program:
Related information of LED header file:
#ifndef _LED_H
#define _LED_H
#include "stm32f10x.h"
#define ON 1
#define OFF 0
#define LED1(a) if (a)\
GPIO_ResetBits(GPIOC,GPIO_Pin_3);\
else\
GPIO_SetBits(GPIOC,GPIO_Pin_3)
#define LED2(a) if (a)\
GPIO_ResetBits(GPIOC,GPIO_Pin_4);\
else\
GPIO_SetBits(GPIOC,GPIO_Pin_4)
#define LED3(a) if (a)\
GPIO_ResetBits(GPIOC,GPIO_Pin_5);\
else\
GPIO_SetBits(GPIOC,GPIO_Pin_5)
void LED_GPIO_Config(void);
#endif
Here is a very important define. For this program, it is very small and not used much, so it is generally not defined like this. But at the same time, we should also see the definition of this program
The skillfulness of.
Then write the relevant GPIO configuration information of led.c,
#include "led.h"
void LED_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_SetBits(GPIOC,GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5);
}
Then there is the problem of calling the main program:
/******************** (C) COPYRIGHT 2013**************************
* File name: main.c
* Description: Project template built using version 3.5.0.
* Experimental platform: Wildfire STM32 development board should be STM32F103VET6
* Library version: ST3.5.0
*
* Author: wit_yuan
* Version: v1.0
* Time: April 27, 2013
**********************************************************************************/
#include "stm32f10x.h"
#include "led.h"
void delay(__IO uint32_t time);
/*
* Function name: main
* Description: Main function
* Input: None
* Output: None
*/
int main(void)
{
LED_GPIO_Config();
LED1(ON);
delay(0x0FFFFFFF);
LED1(OFF);
}
void delay(__IO uint32_t time)
{
for(;time>0;time--);
}
It should be noted that the clock is 72MHZ, so the delay of this program should be more than 30 seconds. The result proved to be about the same time.
Notice:
Since clock-related configuration is used, header files need to be added.
#include "stm32f10x_rcc.h"
Previous article:stm32 learning four
Next article:PWM output based on STM32
Recommended ReadingLatest update time:2024-11-16 13:23
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- VGA display image
- Is there any chip solution with dual adjustable PWM frequency and duty cycle?
- Basic principles and driving waveforms of BLDC six-step commutation method
- [Xianji HPM6750EVKMINI Review] 5# HPM6750 Camera Usage
- MSP430FR604x, MSP430FR504x for Air and Water Flow Metering Applications Datasheet
- I think this is Japanese anime——【Electronic comic series】
- [Xianji HPM6750 Review] Running the Edge AI Framework - TFLM Benchmark
- Analysis of capacitor filtering and EMC rectification suggestions
- Verilog HDL models at different abstraction levels.pdf
- Asking for advice: How to deal with the bit error rate when using usart to RS485 for Huada chip HC32F460?