Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| stm32:peripherals:gpio_input [2016/02/25 08:03] – feur | stm32:peripherals:gpio_input [2022/12/28 08:15] (current) – ruan | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| * The output buffer is disabled. | * The output buffer is disabled. | ||
| * The Schmitt trigger input is active. | * The Schmitt trigger input is active. | ||
| - | * The pull-up and -down resistors are active, according to [[gpio#registers|PUPDR]]. | + | * The pull-up and -down resistors are active, according to [[#PUPDR|PUPDR]]. |
| * Input data is sampled every AHB clock. | * Input data is sampled every AHB clock. | ||
| * Input data register holds I/O state. | * Input data register holds I/O state. | ||
| Line 9: | Line 9: | ||
| \\ {{gpio_input.svg}} \\ \\ | \\ {{gpio_input.svg}} \\ \\ | ||
| - | ===== Programming | + | ===== Programming |
| - | The code snippet bellow shows how to configure a GPIO pin as input. | + | ==== Enable Peripheral ==== |
| - | <code c> | + | Make sure the peripheral is enabled: |
| - | #include " | + | * Enable GPIOx in '' |
| - | GPIOA-> | + | ==== Setup input mode ==== |
| - | GPIOA->PUPDR &= ~(0x3 << 20u); /* Clear existing | + | Configure the MODE and PUPDR register, for every pin that should act as digital input: |
| - | GPIOA-> | + | * Write '' |
| - | + | | |
| - | uint32_t data = GPIOA-> | + | |
| - | </ | + | |
| \\ | \\ | ||
| ===== Configuration Registers ===== | ===== Configuration Registers ===== | ||
| - | ==== MODER - Mode register ==== | + | ==== GPIOx_MODER |
| \\ {{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 - Push-up / pull-down register ==== | + | ==== GPIOx_PUPDR |
| \\ {{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 - Input data register ==== | + | ==== GPIOx_IDR |
| \\ {{gpio_reg_idr.svg}} \\ \\ | \\ {{gpio_reg_idr.svg}} \\ \\ | ||
| - | * Register is read only | + | * Register is read only \\ \\ |
| - | + | ||
| - | ===== Legend ===== | + | |
| - | \\ {{legende.svg}} \\ \\ | ||