STM32 learning three

Publisher:tgdddtLatest update time:2016-10-05 Source: eefocusKeywords:stm32  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. GPIO LED lighting procedure:

      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"

Keywords:stm32  GPIO Reference address:STM32 learning three

Previous article:stm32 learning four
Next article:PWM output based on STM32

Recommended ReadingLatest update time:2024-11-16 13:23

Three different boot modes of STM32
The storage media corresponding to the three boot modes of STM32 are all built-in to the chip, they are: 1. User flash memory: built-in Flash of the chip. 2. SRAM: built-in RAM area of ​​the chip, that is, memory. 3. System memory: a specific area inside the chip. A Bootloader is preset in this area when the chip le
[Microcontroller]
stm32 SysTick (system timer) on rt-thread
Systick has been configured in board.c of rt-thread -- SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND ); 10ms = (72M/100) * (1/72M)s Systick's interrupt function SysTick_Handler() calls rt_tick_increase() to increase the rt_tick value There are several interface functions in clock.c rt_tick_t rt_tick_get(
[Microcontroller]
How to implement STM32 Printf function using standard library
/****************************************************Dividing line*******************************************/ // Add the following code. If printf function is supported, you do not need to select use MicroLIB //Add header file #include stdio.h //Add code #if 1 #pragma import(__use_no_semihosting)              //
[Microcontroller]
How to implement STM32 Printf function using standard library
STM32 MCU ADC learning summary
    Because the company's products need to use AD to detect battery voltage, the requirements are not very high, and I suddenly want to use DMA+ADC+TIM. I thought it was very simple before, but the actual use made me feel ashamed. The problems I encountered made me confused. I kept checking information and testing, and
[Microcontroller]
STM32 MCU ADC learning summary
[51 MCU Quick Start Guide] 2.3: GPIO reads matrix keyboard 8 IO reads 16 keys
Puzhong 51-Single-core-A2 STC89C52 Keil uVision V5.29.0.0 PK51 Prof.Developers Kit Version:9.60.0.0 Hard Knowledge Selected from "Popular 51 Single-Chip Microcomputer Development Strategy_V1.2" Matrix keyboard introduction        When independent buttons are connected to a single-chip microcomputer, each button re
[Microcontroller]
[51 MCU Quick Start Guide] 2.3: GPIO reads matrix keyboard 8 IO reads 16 keys
STM32 register lighting introduction
1. Say it in advance: 1. The initial understanding of stm32 is based on library functions. A bunch of library functions are called to solve the problem. However, if you delve into the library functions, you will eventually find the configuration of registers. 2. Register: It is used to store data. In fact, the con
[Microcontroller]
stm8s gpio port configuration
  Introduction   The general input/output ports of STM8 are used for data transmission between the chip and the outside. An IO port can include up to 8 pins, each of which can be independently programmed as a digital input or digital output port. In addition, some ports may also have multiplexing functions such as ana
[Microcontroller]
stm8s gpio port configuration
STM32 timer timing calculation
Assuming the system clock is 72Mhz, TIM1 is obtained from PCLK2 (72MHz), and TIM2-7 is obtained from PCLK1. The key is to set the clock pre-division number and the value of the automatic reload register period. Basic settings of the timer      1.     TIM_TimeBaseStructure.TIM_Prescaler = 7199; //Clock pre-divisi
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号