Testing SPI with ADXL345 Module
Perform the following steps to test SPI with the ADXL345 module:
-
Connect the ADXL345 module to the 40-pin header as the following:
-
Locate to the following path for test tool, spidev_test.c:
cd /linux/tools/spi
-
Execute the following command under the test tool directory:
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv
Result:The output file is spidev_test in the same directory.
-
Upload spidev_test to VisionFive
2, and change the execution
permission by executing the following:
chmod +x spidev_test
-
Confirm the SPI device.
ls /dev/spidev*
In this output, spidev1.0 is the device name.
-
Execute the following to read the device ID:
./spidev_test -H -O -D /dev/spidev1.0 -v -p \\x80\\x00
-
Execute the following to read the value for multiple registers:
./spidev_test -H -O -D /dev/spidev1.0 -v -p \\xec\\x00\\x00\\x00\\x00\\x00\\x00
-
Execute the following to read:
./spidev_test -H -O -D /dev/spidev1.0 -v -p \\x9e\\x00
-
Execute the following to write:
./spidev_test -H -O -D /dev/spidev1.0 -v -p \\x1e\\xaa
-
Execute the following to read the verification:
./spidev_test -H -O -D /dev/spidev1.0 -v -p \\x9e\\x00