is a small STM32-based project that reads 3-axis acceleration data from an ADXL345 sensor, buffers it for 1 second at 1 kHz, and then transmits it via UART and CAN bus. Perfect for capturing impact or vibration events in embedded systems.
- 🧭 3-axis accelerometer data from ADXL345 via SPI
- ⏱️ 1000 samples per second (1 kHz), total 1000 samples in buffer
- 🟢 Trigger signal via GPIO (rising edge)
- 💾 Data is buffered in RAM, sent after acquisition
- 📤 Data output via UART and optionally via CAN
- 📦 CAN data transmission in chunks with custom protocol
- 🧪 Simple and compact C code, ideal for lab testing or automotive debug setups
STM32 microcontroller with:
- SPI (ADXL345)
- UART (for output)
- GPIO (for trigger input)
- CAN (for data transmission)
- ADXL345 accelerometer (3.3 V logic)
- STM32CubeMX / STM32CubeIDE (for initial setup)
Signal | STM32 Pin | ADXL345 |
---|---|---|
SPI MOSI | e.g. PA7 | SDI |
SPI MISO | e.g. PA6 | SDO |
SPI SCK | e.g. PA5 | SCL |
SPI CS | e.g. PB0 | CS |
Trigger Input | e.g. PA8 | (external source) |
UART TX | e.g. PA9 | (debug terminal) |
CAN TX / RX | any FDCAN-capable pins |
- Boot
- Wait for trigger (PA8 ↑)
- Acquire 1000 XYZ samples (1 ms cadence)
- Transmit
- UART: CSV line per sample
- CAN FD: Header + chunked payload → CRC-8 terminator
Frame | CAN ID | DLC | Payload |
---|---|---|---|
Request | 0x123 |
1 | 0xAB (host → logger) |
Header | 0x321 |
3 | LEN_H , LEN_L , CHUNK_CNT |
Payload | 0x322 … 0x32F |
up to 64 | Raw data bytes (XYZ buffer) |
CRC | 0x330 |
1 | CRC-8 (XOR of LEN + payload) |
- LEN = 2000 bytes (1000 samples × 2 bytes per axis)
- CHUNK_CNT = ceil(LEN / 64)
- CRC is calculated after the final payload frame and sent in its own frame.
Default bitrate: 500 kbit/s nominal.
CAN_Accelerometer_Logger/
├── Core/
│ ├── Src/
│ └── Inc/
├── Drivers/
├── .gitignore
├── README.md
└── LICENSE (CC0-1.0)
This project is licensed under CC0 1.0 Universal (Public Domain Dedication). You can use it freely without attribution – though a ⭐ on GitHub is always appreciated :)
This project is provided "as is" without warranty of any kind, either expressed or implied.
In no event shall the author(s) be liable for any claim, damages, or other liability arising from, out of, or in connection with the use or other dealings in this project.
Made with ❤️ by Styria Electronics for high-performance embedded data acquisition over CAN bus.
🛠️ Contributions welcome!