# yangyuanxin/stm32-i2c-scanner architecture

> Architecture diagram of the GitHub repository yangyuanxin/stm32-i2c-scanner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yangyuanxin/stm32-i2c-scanner
- Repository: https://github.com/yangyuanxin/stm32-i2c-scanner
- Video tour (about a minute): https://gitdiagram.com/yangyuanxin/stm32-i2c-scanner/video

## Overview

This is a standalone STM32F103 I²C address scanner: after boot checks, it probes the 7-bit bus, identifies known addresses, and presents diagnostics on an ST7735 screen with LED feedback. The main application owns the scan/recovery loop and selects progressively slower timing profiles. The README documents floating-bus checks, GPIO self-test, and recovery; the sampled code confirms scan probing, display rendering, and the register-based support layer. Some finer wiring is documented rather than visible in the excerpts.

Main entry points: [`src/main.c`](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c) (Scan state machine), [`include/stm32f103xb.h`](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/include/stm32f103xb.h) (STM32 register definitions), [`src/i2c_bb.c`](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c) (Address probe), [`src/st7735.c`](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/st7735.c) (ST7735 graphics driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Scanner application"]
  node_main["Scan state machine<br/>[main.c]"]
  node_selftest["GPIO self-test<br/>[main.c]"]
  node_buscheck["Bus checks<br/>[main.c]"]
  node_recovery["Bus recovery<br/>[i2c_bb.c]"]
  node_render["Results and diagnostics<br/>[main.c]"]
  node_led["LED indication<br/>[main.c]"]
end

subgraph group_i2c["I2C engine"]
  node_speed["Speed profiles<br/>[i2c_bb.c]"]
  node_scan["Address scan<br/>[i2c_bb.c]"]
  node_probe["Address probe<br/>[i2c_bb.c]"]
  node_floatcheck["Floating-bus validation<br/>[i2c_bb.c]"]
  node_database[("Known-device lookup<br/>[i2c_bb.c]")]
end

subgraph group_display["Display output"]
  node_driver["ST7735 graphics driver<br/>[st7735.c]"]
end

subgraph group_platform["Hardware support"]
  node_hal["HAL compatibility layer<br/>[hal_stub.c]"]
  node_registers["STM32 register definitions<br/>[stm32f103xb.h]"]
end

node_user(("Technician"))
node_target(("I2C target devices"))
node_lcd(("ST7735 LCD"))

node_user -->|"powers on"| node_main
node_main -->|"runs at boot"| node_selftest
node_main -->|"checks bus"| node_buscheck
node_main -->|"sets timing"| node_speed
node_main -->|"requests scan"| node_scan
node_main -->|"requests recovery"| node_recovery
node_scan -->|"checks pull-up"| node_floatcheck
node_scan -->|"probes addresses"| node_probe
node_probe -->|"sends address"| node_target
node_target -->|"ACKs or NACKs"| node_probe
node_main -->|"looks up devices"| node_database
node_main -->|"renders results"| node_render
node_render -->|"draws interface"| node_driver
node_driver -->|"sends SPI display data"| node_lcd
node_main -->|"signals device count"| node_led
node_selftest -->|"tests GPIO"| node_registers
node_buscheck -->|"reads bus lines"| node_registers
node_recovery -->|"toggles bus GPIO"| node_registers
node_probe -->|"bit-bangs GPIO"| node_registers
node_driver -->|"controls SPI and GPIO"| node_registers
node_main -->|"initializes and delays"| node_hal
node_hal -->|"accesses hardware"| node_registers

click node_main "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c"
click node_selftest "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c"
click node_buscheck "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c"
click node_recovery "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c"
click node_speed "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c"
click node_scan "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c"
click node_probe "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c"
click node_floatcheck "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c"
click node_database "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c"
click node_render "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c"
click node_led "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c"
click node_driver "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/st7735.c"
click node_hal "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/hal_stub.c"
click node_registers "https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/include/stm32f103xb.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_selftest,node_buscheck,node_recovery,node_render,node_led toneBlue
class node_speed,node_scan,node_probe,node_floatcheck,node_database toneAmber
class node_driver toneMint
class node_hal,node_registers toneRose
class node_user,node_target,node_lcd toneIndigo
```

## Components

### Scanner application

- [Scan state machine](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c): `src/main.c`
- [GPIO self-test](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c): `src/main.c`
- [Bus checks](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c): `src/main.c`
- [Bus recovery](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c): `src/i2c_bb.c`
- [Results and diagnostics](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c): `src/main.c`
- [LED indication](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/main.c): `src/main.c`

### I2C engine

- [Speed profiles](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c): `src/i2c_bb.c`
- [Address scan](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c): `src/i2c_bb.c`
- [Address probe](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c): `src/i2c_bb.c`
- [Floating-bus validation](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c): `src/i2c_bb.c`
- [Known-device lookup](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/i2c_bb.c): `src/i2c_bb.c`

### Display output

- [ST7735 graphics driver](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/st7735.c): `src/st7735.c`

### Hardware support

- [HAL compatibility layer](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/src/hal_stub.c): `src/hal_stub.c`
- [STM32 register definitions](https://github.com/yangyuanxin/stm32-i2c-scanner/blob/main/include/stm32f103xb.h): `include/stm32f103xb.h`

### Other components

- **Technician**
- **I2C target devices**
- **ST7735 LCD**

## Connections

- Technician → Scan state machine: powers on
- Scan state machine → GPIO self-test: runs at boot
- Scan state machine → Bus checks: checks bus
- Scan state machine → Speed profiles: sets timing
- Scan state machine → Address scan: requests scan
- Scan state machine → Bus recovery: requests recovery
- Address scan → Floating-bus validation: checks pull-up
- Address scan → Address probe: probes addresses
- Address probe → I2C target devices: sends address
- I2C target devices → Address probe: ACKs or NACKs
- Scan state machine → Known-device lookup: looks up devices
- Scan state machine → Results and diagnostics: renders results
- Results and diagnostics → ST7735 graphics driver: draws interface
- ST7735 graphics driver → ST7735 LCD: sends SPI display data
- Scan state machine → LED indication: signals device count
- GPIO self-test → STM32 register definitions: tests GPIO
- Bus checks → STM32 register definitions: reads bus lines
- Bus recovery → STM32 register definitions: toggles bus GPIO
- Address probe → STM32 register definitions: bit-bangs GPIO
- ST7735 graphics driver → STM32 register definitions: controls SPI and GPIO
- Scan state machine → HAL compatibility layer: initializes and delays
- HAL compatibility layer → STM32 register definitions: accesses hardware
