GPIO
The stm32f407VG microcontroller has a total of 5×16 PA-PE and a total of 80 multiplexed IO ports. Each general I/O port has four 32-bit configuration registers (GPIOx_MODERGPIOx_OTYPERGPIOx_OSPEEDRGPIOx_PUPDR), two 32-bit data registers (GPIOx_IDR and GPIOx_ODR), a 32-bit set/reset register (GPIOx_BSRR), a 32-bit lock register (GPIOx_LCKR) and two 32-bit alternate function selection registers (GPIOx_AFRHGPIOx_AFRL).
Setup steps:
1. Enable the relevant clock
2. Set the corresponding IO port as input or output
3. Set the input\output type
4. Set the output speed (if set to input, skip this step)
5. If the output speed is >= 50M, turn on the compensation unit
6. Set the pull-up and pull-down registers
7. Operate through the reset register and input and output data register.
program:
[cpp] view plaincopy
/************************************
Title: Exercise on operating GPIO
Software platform: IAR for ARM6.21
Hardware platform: stm32f4-discovery
Main frequency: 168M
author: Xiaochuan
data: 2012-01-16
*************************************/
#include
uint32_t Gb_TimingDelay;
void Delay(uint32_t nTime);
void main ()
{
SysTick_Config(SystemCoreClock / 1000); //Set systemtick one millisecond interrupt
RCC->AHB1ENR |= 0x00000008; //Enable GPIOD clock
RCC->APB2ENR |= (1<<14); //Enable syscfg clock
GPIOD->MODER &= 0x00FFFFFF; //Set PD12,13,14,15 output
GPIOD->MODER |= 0x55000000;
GPIOD->OTYPER &= 0xFFFF0FFF; //Set PD12,13,14,15 push-pull output
GPIOD->OSPEEDR &= 0x00FFFFFF; //PD12,13,14,15 speed 100m
GPIOD->OSPEEDR |= 0xff000000;
SYSCFG->CMPCR = 0x00000001; //Use IO compensation unit,
//When the GPIO speed exceeds 50M, consider using this setting
GPIOD->PUPDR &= 0x00FFFFFF; //PD12,13,14,15 no pull-up no pull-down
GPIOD->BSRRH = 0xf000; //reset register GPIOx_BSRRH, write only
//set register GPIOx_BSRRL, write only
while(1)
{
GPIOD->BSRRH = 0xf000;
GPIOD->BSRRL = 0x1000;
Delay(500);
GPIOD->BSRRH = 0xf000;
GPIOD->BSRRL = 0x1000<<1;
Delay(500);
GPIOD->BSRRH = 0xf000;
GPIOD->BSRRL = 0x1000<<2;
Delay(500);
GPIOD->BSRRH = 0xf000;
GPIOD->BSRRL = 0x1000<<3;
Delay(500);
}
}
void Delay(uint32_t nTime)
{
Gb_TimingDelay = nTime;
while(Gb_TimingDelay != 0);
}
void SysTick_Handler(void)
{
if (Gb_TimingDelay != 0x00)
{
Gb_TimingDelay--;
}
}
Previous article:VR ELF file generation and burning
Next article:STM32F407 ADC (operation register)
Recommended ReadingLatest update time:2024-11-16 15:20
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
- Working principle, functional characteristics and classification of photoelectric liquid level sensors
- EEWORLD University Hall--Detailed explanation of MATLAB image functions and their applications
- I need help, stlink v2 cannot be recognized and the firmware version cannot be seen
- FPGA Power Consumption
- Easily extend the battery life of the charging box of TWS true wireless Bluetooth headsets
- MSP430FR2355 LaunchPad Development Kit
- NUCLEO_G431RB Review - UART Questions
- Using a fuel gauge chip to achieve fast and intelligent charging of dual-series lithium batteries
- Here is a disassembly picture of ASUS Mars15 VX60GT9750
- 【GD32E231 DIY】Human infrared detection (EXTI)