To interface the ADXL345 three-axis accelerometer with an STM32 microcontroller, you can use either I2C or SPI (the sensor supports both). Below is a complete guide using I2C with STM32 HAL, which is the most common and beginner-friendly setup.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
1. ADXL345 Overview
- 3-axis accelerometer
- Digital output via I2C or SPI
- Resolution: 10-bit (±2g to ±16g range)
- Address: 0x53 (when ALT address pin = LOW)
2. Hardware Connections (I2C Mode)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Add 4.7kΩ pull-up resistors to SDA and SCL lines if needed.
3. STM32CubeMX Setup
- Enable I2C1
- Assign pins (e.g., PB6 = SCL, PB7 = SDA)
- Set I2C clock speed (100 kHz or 400 kHz)
- Generate code with HAL drivers
4. ADXL345 Register Summary
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
5. STM32 I2C Code Example (HAL)
a) Read Device ID
b) Initialize Sensor
c) Read Acceleration Data
6. Notes on Scaling
- Scale factor: 4 mg/LSB at ±2g range
- To convert to m/s²: multiply by 9.81
7. Best Practices
- Add delays after writing to configuration registers.
- Use DMA or interrupts for real-time applications.
- Verify DEVID returns 0xE5 to confirm communication.