Testing SPI with ADXL345 Module

Perform the following steps to test SPI with the ADXL345 module:

  1. Connect the ADXL345 module to the 40-pin header as the following:
    Figure 1. Connect ADXL345 Module to the Header
  2. Locate to the following path for test tool, spidev_test.c:
    cd /linux/tools/spi
  3. 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.

  4. Upload spidev_test to VisionFive 2, and change the execution permission by executing the following:
    chmod +x spidev_test
  5. Confirm the SPI device.
    ls /dev/spidev*
    Figure 2. Example Output

    In this output, spidev1.0 is the device name.

  6. Execute the following to read the device ID:
    ./spidev_test -H -O -D /dev/spidev1.0 -v -p \\x80\\x00
  7. 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
  8. Execute the following to read:
    ./spidev_test -H -O -D /dev/spidev1.0 -v -p \\x9e\\x00
  9. Execute the following to write:
    ./spidev_test -H -O -D /dev/spidev1.0 -v -p \\x1e\\xaa
  10. Execute the following to read the verification:
    ./spidev_test -H -O -D /dev/spidev1.0 -v -p \\x9e\\x00