Microcontrollers provide a number of I2C controllers on board that can be bound to specific pins using alternate functions. On our reference board, to enable the I2C1 bus, we activate the clock gating, and start the initialization procedure by accessing the control, data, and status register mapped in the peripherals memory region:
#define APB1_CLOCK_ER (*(volatile uint32_t *)(0x40023840))#define APB1_CLOCK_RST (*(volatile uint32_t *)(0x40023820))#define I2C1_APB1_CLOCK_ER_VAL (1 << 21)
The I2C1 controller on STM32F407 is associated with pins PB6 and PB9 when they are configured with the AF4 alternate function:
#define I2C1_PIN_AF 4#define I2C1_SCL 6#define I2C1_SDA 9#define GPIO_MODE_AF (2)static void i2c1_pins_setup(void) ...