|
1 | 1 | # 📦 CAN Accelerometer Logger |
| 2 | + 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. |
2 | 3 |
|
3 | 4 | [](LICENSE) |
4 | 5 | []() |
5 | 6 | []() |
6 | 7 | []() |
7 | 8 |
|
8 | | -A compact STM32-based motion sensor module using an ADXL345 digital accelerometer. |
9 | | -This device logs 3-axis acceleration data at 1 kHz for 1 second (1000 samples) and then transmits the data via **CAN** and **UART**. |
10 | | - |
11 | | ---- |
12 | | - |
13 | 9 | ## 🚀 Features |
14 | 10 |
|
15 | | -- ✅ SPI communication with ADXL345 |
16 | | -- ✅ Buffered sampling at **1 kHz** for 1 second |
17 | | -- ✅ Data output via: |
18 | | - - UART (CSV format) |
19 | | - - CAN bus (fragmented transfer with optional header and CRC) |
20 | | -- ✅ Trigger via GPIO (e.g. rising edge or external button) |
21 | | -- ✅ Visual feedback via onboard LED |
22 | | - |
23 | | ---- |
24 | | - |
25 | | -## 🧠 Technical Overview |
| 11 | +- 🧭 3-axis accelerometer data from ADXL345 via SPI |
| 12 | +- ⏱️ 1000 samples per second (1 kHz), total 1000 samples in buffer |
| 13 | +- 🟢 Trigger signal via GPIO (rising edge) |
| 14 | +- 💾 Data is buffered in RAM, sent after acquisition |
| 15 | +- 📤 Data output via UART and optionally via CAN |
| 16 | +- 📦 CAN data transmission in chunks with custom protocol |
| 17 | +- 🧪 Simple and compact C code, ideal for lab testing or automotive debug setups |
26 | 18 |
|
27 | | -| Feature | Value | |
28 | | -|----------------|--------------------------| |
29 | | -| MCU | STM32G4xx (e.g. G431) | |
30 | | -| Sensor | ADXL345 (±8g range) | |
31 | | -| Sampling Rate | 1000 Hz (1 kHz) | |
32 | | -| Buffer Size | 1000 samples (x,y,z) | |
33 | | -| Interface | SPI (ADXL), UART, CAN | |
34 | | -| CAN Speed | 500 kbit/s | |
35 | | -| CRC | CRC8 for data integrity | |
| 19 | +## ⚙️ Requirements |
36 | 20 |
|
37 | | ---- |
| 21 | +STM32 microcontroller with: |
38 | 22 |
|
39 | | -## ⚙️ Trigger Modes |
| 23 | +- SPI (ADXL345) |
| 24 | +- UART (for output) |
| 25 | +- GPIO (for trigger input) |
| 26 | +- CAN (for data transmission) |
| 27 | +- ADXL345 accelerometer (3.3 V logic) |
| 28 | +- STM32CubeMX / STM32CubeIDE (for initial setup) |
40 | 29 |
|
41 | | -| Mode | Description | |
42 | | -|------------|--------------------------------------| |
43 | | -| GPIO | Starts on rising edge | |
44 | | -| Button | Optional fallback (User button) | |
| 30 | +## 🔌 Wiring |
45 | 31 |
|
46 | | ---- |
| 32 | +| Signal | STM32 Pin | ADXL345 | |
| 33 | +|--------------|------------|----------------| |
| 34 | +| SPI MOSI | e.g. PA7 | SDI | |
| 35 | +| SPI MISO | e.g. PA6 | SDO | |
| 36 | +| SPI SCK | e.g. PA5 | SCL | |
| 37 | +| SPI CS | e.g. PB0 | CS | |
| 38 | +| Trigger Input| e.g. PA8 | (external source) | |
| 39 | +| UART TX | e.g. PA9 | (debug terminal) | |
| 40 | +| CAN TX / RX | any FDCAN-capable pins | |
47 | 41 |
|
48 | | -## 🖧 CAN Communication |
| 42 | +## 🧪 Example Workflow |
49 | 43 |
|
50 | | -- The device sends a header frame with total data length. |
51 | | -- Followed by multiple frames (8 bytes each). |
52 | | -- Designed to work with another STM32 as a CAN receiver & I2C bridge. |
| 44 | +1. Startup |
| 45 | +2. Wait for trigger input (PA8 HIGH) |
| 46 | +3. Sample 1000 accelerometer values (XYZ) |
| 47 | +4. After sampling: |
| 48 | + - Send data over UART (CSV format) |
| 49 | + - Send header + chunked payload via CAN |
53 | 50 |
|
54 | | ---- |
| 51 | +## 💬 CAN Protocol Overview |
55 | 52 |
|
56 | | -## 📡 UART Output |
| 53 | +- **Request:** ID 0x123, single byte 0xAB to request data |
| 54 | +- **Header:** ID 0x321, first frame = 2 bytes length (e.g. 0x27 0x11 = 10001) |
| 55 | +- **Payload:** subsequent frames with raw buffer data |
57 | 56 |
|
58 | | -- Data is streamed as comma-separated values (CSV): |
59 | | - ``` |
60 | | - 124,0,-1032 |
61 | | - 123,1,-1033 |
62 | | - ... |
63 | | - ``` |
| 57 | +## 📂 Folder Structure |
64 | 58 |
|
65 | | ---- |
| 59 | +``` |
| 60 | +CAN_Accelerometer_Logger/ |
| 61 | +├── Core/ |
| 62 | +│ ├── Src/ |
| 63 | +│ └── Inc/ |
| 64 | +├── Drivers/ |
| 65 | +├── .gitignore |
| 66 | +├── README.md |
| 67 | +└── LICENSE (CC0-1.0) |
| 68 | +``` |
66 | 69 |
|
67 | | -## 🛠️ Build Requirements |
| 70 | +## 📄 License |
68 | 71 |
|
69 | | -- STM32CubeIDE or Makefile toolchain |
70 | | -- STM32G4 family MCU (e.g. Nucleo-G431RB) |
71 | | -- ADXL345 accelerometer |
72 | | -- Proper CAN transceivers (e.g. TJA1050) |
| 72 | +This project is licensed under [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/) (Public Domain Dedication). You can use it without attribution – though a ⭐ on GitHub is always appreciated :) |
73 | 73 |
|
74 | | ---- |
| 74 | +## ✨ Credits |
75 | 75 |
|
76 | | -## 📎 License |
| 76 | +Made with ❤️ by **Styria Electronics** for high-performance embedded data acquisition over CAN bus. |
77 | 77 |
|
78 | | -This project is licensed under the MIT License. |
| 78 | +🛠️ Contributions welcome! |
0 commit comments