How to set up the STM32 input pull-up and pull-down registers

Publisher:国宝集团Latest update time:2018-08-26 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In output mode: ODR is the data output register,
but in input mode, it is also used to configure the pull-up and pull-down settings.


In the key input experiment in the Alientek source code, there is the following initialization code:
void KEY_Init(void){
      RCC->APB2ENR|=1<<2; //Enable PORTA clock
    GPIOA->CRL&=0XFFFFFFF0; //PA0 is set as input      
    GPIOA->CRL|=0X00000008;  
    GPIOA->CRH&=0X0F0FFFFF; //PA13,15 are set as input      
    GPIOA->CRH|=0X80800000;                   
    GPIOA->ODR|=1<<13; //PA13 is pulled up, PA0 is pulled down by default
    GPIOA->ODR|=1<<15; //PA15 is pulled up
}
Users often ask why the port is set as input, and then the output register must be written, GPIOA->ODR|=1<<15; //There is indeed no description of PA15 pull-up
in the Chinese data sheet. The following is from the English manual (found on the Internet):


    That is, when the port is set to pull-up/pull-down input, the pull-down input or pull-up input is set by setting

the corresponding bit of GPIOx->ODR to 0 or 1. 0000 (0) Analog input, usually used for AD sampling  0100 (4) Floating input, if there is an external pull-up or pull-down, this  1000 (8) Pull-up/pull-down input can be used to enable the internal pull-up/pull-down structure, so that the port is set to a certain level when idle. The specific level is determined by GPIOx->ODR. Setting it to 1 means high level, and setting it to 0 means low level. In the library function, this is how it is implemented in void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)















  1. // Set the pull-up and pull-down input mode by writing ODR

  2.         /* Reset the corresponding ODR bit */

  3.         if(GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)

  4.         {

  5.           GPIOx->BRR =(((u32)0x01)<< pinpos); //Write ODR corresponding bit = 0

  6.         }

  7.         /*Set the corresponding ODR bit */

  8.         if(GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)

  9.         {

  10.           GPIOx->BSRR =(((u32)0x01)<< pinpos); //Write ODR corresponding bit = 1

  11.         }




ODR Register


Keywords:STM32 Reference address:How to set up the STM32 input pull-up and pull-down registers

Previous article:STM32 GPIO's 8 operating modes and related configuration registers
Next article:STM32 learn three GPIO operation

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

STM32---Key learning
#include "stm32f10x.h"   GPIO_InitTypeDef GPIO_InitStructure;//声明GPIO_InitStructure   void LED_Init() {  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //Turn on GPIOA clock   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //Push-pull output  GPIO_InitStructure.GPIO_S
[Microcontroller]
STM32 key EXTI mode using ST3.0.0 library
Steps to configure IO as EXTI interrupt: 1: Enable the EXTI Line clock and the second function clock. 2: Configure EXTI Line interrupt priority (NVIC) 3: Configure EXTI Line IO (which pin, input mode, initialization) 4: Configure the pin as the interrupt source of EXTI Line (GPIO operation) and configure the wor
[Microcontroller]
Uip transplantation in STM32 platform to establish UDP link
Data transmission is achieved by establishing a UDP connection on STM32. In the previous section, it was mentioned that the lightweight TCP/IP protocol stack Uip is used. To create a UDP connection in the Uip protocol, the following steps are required: The first step is to open the configuration items that support the
[Microcontroller]
STM32 GPIO Application Notes
1                      The input and output pins of STM32 have the following 8 possible configurations: (4 inputs + 2 outputs + 2 multiplexed outputs) ①Floating  input_IN_FLOATING ②With  pull-up input_IPU    ③With  pull-down input_IPD                      ④Analog  input_AIN ⑤Open  drain output_OUT_OD         
[Microcontroller]
Detailed explanation of STM32_NVIC registers
In MDK, the registers related to NVIC are defined as follows:   typedef struct   {         vu32 ISER ; //2 32-bit interrupt enable registers correspond to 60 maskable interrupts       u32 RESERVED0 ;               vu32 ICER ; //2 32-bit interrupt disable registers correspond to 60 maskable interrupts       u32 RSERVED
[Microcontroller]
Detailed explanation of STM32_NVIC registers
Description of assert_param() in stm32 program
The subroutines all have assert_param(....), as follows: What is the use of this sentence? ? ? Should it be OK to delete it? ? void TIM1_TimeBaseInit(u16 TIM1_Prescaler,                        TIM1_CounterMode_TypeDef TIM1_CounterMode,                        u16 TIM1_Period,                        u8 TIM1_Repetition
[Microcontroller]
stm32 advanced timer relearning
I recently used timers in a project, so I decided to relearn them. I used them only for simple pwm generation and interrupt processing before, and never studied them in depth. Today, I took this opportunity to relearn advanced timers. Once you learn advanced timers, you will have no problem with basic timers. In genera
[Microcontroller]
stm32 advanced timer relearning
Summary of problems encountered in STM32 IAP upgrade
1.Serial communication problem 1. The TTL levels at both ends of the serial communication must be consistent. Depending on the selected chip, they should be either 3.3V or 5V. When the levels at both ends are inconsistent, data cannot be received. When there is no problem with the detection program, etc. but data ca
[Microcontroller]
Summary of problems encountered in STM32 IAP upgrade
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号