Digital input

A GPIO pin configured in input mode detects the logic level of the voltage applied to it. The logic value of all the input pins on a GPIO controller can be read from the input data register (IDR). On the reference board, the pin A0 is connected to the user button, so the status of the button can be read at any time while the application is running.

The GPIOA controller can be turned on by clock gating:

#define AHB1_CLOCK_ER (*(volatile uint32_t *)(0x40023830))#define GPIOA_AHB1_CLOCK_ER (1 << 0)

The controller itself is mapped at address 0x40020000:

#define GPIOA_BASE 0x40020000#define GPIOA_MODE (*(volatile uint32_t *)(GPIOA_BASE + 0x00))#define GPIOA_IDR (*(volatile uint32_t *)(GPIOA_BASE + 0x10))

To set up the pin for input, ...

Get Embedded Systems Architecture now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.