Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
stm32:peripherals:gpio_input [2016/02/25 08:23] feurstm32:peripherals:gpio_input [2022/12/28 08:15] (current) ruan
Line 9: Line 9:
 \\ {{gpio_input.svg}} \\ \\ \\ {{gpio_input.svg}} \\ \\
  
-===== Programming example =====+===== Programming Instructions =====
  
-The code snippet bellow shows how to configure and use a GPIO pin as input.+==== Enable Peripheral ====
  
-<code c> +Make sure the peripheral is enabled: 
-#include "reg_stm32f4xx.h"+  * Enable GPIOx in ''RCC->AHBENR[0]''.
  
-/* Configure GPIO pin A.10 as input. */ +==== Setup input mode ====
-GPIOA->MODER &~(0x3 << 20u);    /* Clear existing mode bits 20 and 21. */+
  
-GPIOA->PUPDR &= ~(0x3 << 20u);    /Clear existing pull-up/-down bits 20 and 21. */ +Configure the MODE and PUPDR register, for every pin that should act as digital input: 
-GPIOA->PUPDR |= (0x1 << 20u);     /* Set pin 10 to pull-up mode*/ +  * Write ''0x00'' to the corresponding fields in ''GPIOx->MODE''
- +  Configure pull-up / -down in ''GPIOx->PUPDR''.
-/* Read from GPIO pin A.10. */ +
-uint32_t data = GPIOA->IDR;       /* Read the input data register. */ +
-</code>+
 \\ \\
  
 ===== Configuration Registers ===== ===== Configuration Registers =====
  
-==== MODER ==== +==== GPIOx_MODER - GPIO port mode register ====
- +
-Mode register+
  
 \\ {{gpio_reg_common.svg}} \\ \\ \\ {{gpio_reg_common.svg}} \\ \\
  
-|< 100% 5em >| +|< 100% 5em 5em >| 
-|00|Input mode (reset state)|+|Pin x|00|Input mode (reset state)|
  
-==== PUPDR ==== +==== GPIOx_PUPDR - GPIO port pull-up / pull-down register ====
- +
-Push-up / pull-down register+
  
 \\ {{gpio_reg_common.svg}} \\ \\ \\ {{gpio_reg_common.svg}} \\ \\
  
-|< 100% 5em >| +|< 100% 5em 5em >| 
-|00|No pull-up, pull-down (reset state)| +|Pin x|00|No pull-up, pull-down (reset state)| 
-|01|Pull-up| +|:::|01|Pull-up| 
-|10|Pull-down|+|:::|10|Pull-down|
  
 ===== Data Registers ===== ===== Data Registers =====
  
-==== IDR ==== +==== GPIOx_IDR - Port input data register ====
- +
-Input data register+
  
 \\ {{gpio_reg_idr.svg}} \\ \\ \\ {{gpio_reg_idr.svg}} \\ \\
  
-* Register is read only +* Register is read only \\ \\
- +
-===== Legend =====+
  
-\\ {{legende.svg}} \\ \\ 
  • stm32/peripherals/gpio_input.1456388607.txt.gz
  • Last modified: 2016/02/25 08:23
  • by feur