STM32F407 GPIO (operation register)

Publisher:MysticEssenceLatest update time:2018-09-20 Source: eefocusKeywords:stm32f407  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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--;  

  }  

}  


Keywords:stm32f407  GPIO Reference address:STM32F407 GPIO (operation register)

Previous article:VR ELF file generation and burning
Next article:STM32F407 ADC (operation register)

Recommended ReadingLatest update time:2024-11-16 15:20

STM32GPIO——Use of fast IO
Each GPIO port of STM32 has two special registers, GPIOx_BSRR and GPIOx_BRR registers, through which the corresponding GPIOx port can be directly set to '1' or '0'. Each of the upper 16 bits of GPIOx_BSRR corresponds to each bit of port x. If a position in the upper 16 bits is '1', the corresponding bit of port x is c
[Microcontroller]
STM32F407 general timer
The general purpose timers (TIM2 to TIM5) consist of a 16-bit or 32-bit auto-reload counter driven by a programmable divider. They can be used for a variety of purposes, including measuring the pulse length of an input signal (input capture) or generating an output waveform (output compare and PWM). The pulse length a
[Microcontroller]
STM32 learning notes - using function library programming to control GPIO port output
After looking at many people's codes on the Internet and the routines provided by various development boards, I found that most of them use the officially released function library for programming. After searching, I found that using function library for programming can simplify the development process and does not nee
[Microcontroller]
STM32 learning notes - using function library programming to control GPIO port output
Use J-FLASH to burn stm32F407
open data file- connect- program- start application Hardware connection completed open data file The software file box appears connected The software displays connected successfully. program (Do not operate this item and proceed directly to the next step without hardware response) start ap
[Microcontroller]
Use J-FLASH to burn stm32F407
STM32 GPIO interrupt example
Preface: I am currently developing a rangefinder data summary display instrument. I started learning hardware in February 2017. I am good at software. I spent 1 month drawing the schematic diagram and half a month drawing the PCB board. In the middle, I spent 2 months using JAVA to develop an intermediate version of t
[Microcontroller]
11. GPIO principle and configuration (marquee, buzzer, button)
1. STM32 GPIO firmware library function configuration method 1. Delete some unused firmware library files in the project as needed and keep the useful firmware library files 2. Comment out these unused header files in stm32f10x_conf.h 3. The IO port of STM32 can be configured by software into the following 8 mod
[Microcontroller]
11. GPIO principle and configuration (marquee, buzzer, button)
arm7 Litian Electronics lpc2148 GPIO one buzzer test program
The experiment uses the output function of P0.22 to control the buzzer. The program sets PINSEL0 to connect P0.22 to GPIO, and sets it to output state through IO0DIR; then sets and clears P0.22 port through IO0DET and IO0CLR to control the buzzer. #include NXP/iolpc2148.h void Delay(unsigned long n); main() {   PI
[Microcontroller]
arm7 Litian Electronics lpc2148 GPIO one buzzer test program
STM32 Notes (I) GPIO port configuration
GPIO port usage: 1. The entire GPIO and AFIO  series supports   GPIO registers (1) Two 32-bit configuration registers (GPIOx_CRL, GPIOx_CRH); (2) Two 32-bit data registers (GPIOx_IDR, GPIOx_ODR); (3) A 32-bit set/reset register (GPIOx_BSRR); (4) A 16-bit reset register (GPIOx_BRR); (5) A 32-bit latch (GPIOx_LC
[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号