MA35D1 How to use SPI ?
Answer.
- Modify ma35d1-iot-512m.dts and add the configuration of spidev0.
Enable "User mode SPI device driver support" in the kernel menuconfig. This step can generate a spidev0.0 node.
Code: Select all
&spi2 { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_spi2>; spidev2: spi@0 { compatible = "adi,adxl345"; reg = <0>; spi-max-frequency = <5000000>; }; };
Code: Select all
Device Drivers SPI support <*> User mode SPI device driver support
- Use spidev_test application in buildroot to test.
Code: Select all
$ make menuconfig
Code: Select all
Target packages Debugging, profiling and benchmark → [*] spidev_test
- Loop back test: MOSI and MISO are connected together, and the test results are that the data of TX and RX are the same.
Code: Select all
# spidev_test -D /dev/spidev2.0 -v -p 1234
Code: Select all
spi mode: 0x0 bits per word: 8 max speed: 500000 Hz (500 KHz) TX | 31 32 33 34 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ | 1234 RX | 31 32 33 34 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ | 1234 #
- For example:
MA35 SPI2 is connected with adxl345 (a three-axis accelerometer). You will find that the data read by MA35 SPI2 is incorrect.
Through logic analyzer analysis, it was found that the SPI2 mode was incorrect. The datasheet of adxl345 is SPI mode 3. Therefore you need to modify ma35d1.dtsi and set spi2 to mode=3.
Code: Select all
spi2: spi@40620000 { ... spimode = <3>; ... };
#MA35 , #SPI
.