O'Reilly logo

Embedded Systems Architecture by Daniele Lacamera

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming the controller

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required