STM32 Example

STM32 I2C Scanner Example

Scan I2C bus for connected devices.

Code Example

for(uint8_t addr=1; addr<128; addr++)
{
  if(HAL_I2C_IsDeviceReady(&hi2c1, addr<<1, 1, 10)==HAL_OK)
  {
    // device found
  }
}

How it works

This STM32 example demonstrates basic peripheral configuration and HAL usage.

Frequently asked questions

Can I use STM32CubeIDE?

Yes. These examples are intended for STM32CubeIDE and STM32 HAL drivers.

Can I modify the GPIO pins?

Yes. Update GPIO pin definitions according to your board schematic.