This video provides a comprehensive tutorial on implementing the Serial Peripheral Interface (SPI) protocol on the CH32V003 microcontroller, building upon previous tutorials in the series. The demonstration utilizes an ADXL345 3-axis accelerometer sensor, wired for 4-wire SPI communication, to illustrate data transfer. The presenter details the hardware setup, including the CH32V003, a debugger, and a USB-to-UART converter, and conducts the software development within the MounRiver Studio v2 IDE. Key aspects covered include the configuration of GPIO pins for SPI, a comparison of SPI's full-duplex capabilities and chip-select advantages over I²C, and the creation of custom functions for SPI data transfer, register reading, and writing. The video culminates in reading and processing the accelerometer's raw data, converting it to G-units, and visualizing the real-time acceleration data on a serial plotter, highlighting the high-speed data acquisition capabilities.
Summarizing the CH32V003 SPI Tutorial with ADXL345 Accelerometer
0:00 Introduction to SPI: The video continues a CH32V003 tutorial series by focusing on the SPI communication protocol, comparing it to previously covered topics like I²C and timers.
Demonstrates SPI communication using an ADXL345 3-axis accelerometer sensor.
The sensor is wired according to the 4-wire SPI protocol: Chip Select (CS), Master Out Slave In (MOSI), Master In Slave Out (MISO), and Serial Clock (SCK).
Uses the CH32V003F4P6 microcontroller programmed via an SWIO debugger module, with serial communication (UART) handled by a USB-to-UART converter on the debugger.
1:39 Software Development Environment: All software is implemented in WCH's MounRiver Studio, specifically version 2, which the presenter praises for its improvements.
Reads 6 bytes from 0x32 (DATAX0 register), which contains the X, Y, Z acceleration values (two 8-bit bytes per axis). The multi-byte read feature automatically increments the address.
Combines the two 8-bit bytes for each axis into a single 16-bit integer (e.g., (buffer[1] << 8) | buffer[0]).
40:01 Conversion to G-Units (Floating Point Emulation):
Due to microcontroller limitations with floating-point numbers, a trick is used:
Raw data is scaled up by 10,000 and divided by the LSB value (256) to get an integer representing G * 10,000.
The whole and fractional parts are then extracted for printing using integer division and modulo operations.
Prints the X, Y, Z acceleration values in a specific comma-separated format to the serial terminal.
Demonstrates using the Arduino IDE's Serial Plotter to visualize the real-time G-force readings for each axis as the accelerometer is tilted, confirming proper functionality.
48:40 Conclusion & Resources: Discusses further applications like tap detection and vibration analysis. Encourages viewers to visit the accompanying website for a detailed article and GitHub for the source code, and to support the channel through membership.