Back to lab

CH32V003 ADXL345 Accelerometer Integration

Interfacing a 3-axis accelerometer with the cheapest RISC-V microcontroller. Bare-metal I2C driver and motion detection on a $0.10 chip.

CH32V003RISC-VI2CAccelerometerEmbedded

The Setup

The ADXL345 is a popular 3-axis accelerometer that communicates via I2C or SPI. For this project, I'm using I2C to connect it to the CH32V003 — a RISC-V microcontroller that costs less than a resistor.

I2C Configuration

The CH32V003's I2C peripheral needs careful configuration. Clock stretching must be enabled, and the GPIO pins need to be set to alternate function open-drain mode.

Reading Acceleration Data

The ADXL345 stores acceleration data in six registers (two bytes per axis). A burst read starting at register 0x32 gives us X, Y, and Z values in two's complement format.

Motion Detection

Using the ADXL345's built-in tap and activity detection, we can trigger interrupts on the CH32V003 for motion-based applications — all running on less than 2KB of RAM.

shakir.sd

Stay hungry. Stay foolish.

© 2026 Shakir Abdulrahim. All rights reserved.