硬件:wukongpi H3
系统:ubantu
镜像:Orangepizerolts_2.0.8_ubuntu_bionic_server_linux5.4.27.img
引脚图:
1、spi
//1、系统默认关闭了SPI,打开该文件:
vi /boot/orangepiEnv.txt
//2、输入以下内容:
overlays=spi-spidev
param_spidev_spi_bus=1 #修改为开发板所支持的对应的spi 总线号
//3、保存后重启
reboot
重启后进入dev可以看到刚开启的spi
spi功能可以用杜邦线将MOSI和MISO短接,进行自收发的数据测试。 简单写了一个spi驱动测试:
测试结果:
root@orangepizerolts:~# ls
SPI_test.zip
root@orangepizerolts:~# unzip SPI_test.zip
Archive: SPI_test.zip
inflating: SPI_test/Makefile
inflating: SPI_test/spi_main.cpp
inflating: SPI_test/SpiDevice.cpp
inflating: SPI_test/SpiDevice.h
root@orangepizerolts:~# ls
SPI_test SPI_test.zip
root@orangepizerolts:~# cd SPI_test/
root@orangepizerolts:~/SPI_test# ls Makefile SpiDevice.cpp SpiDevice.h spi_main.cpp root@orangepizerolts:~/SPI_test# make make: Warning: File 'Makefile' has modification time 27539 s in the future g++ -Wall -std=c++11 -c spi_main.cpp spi_main.cpp: In function ‘int main()’: spi_main.cpp:22:9: warning: unused variable ‘num’ [-Wunused-variable] int num =10;
^~~
g++ -Wall -std=c++11 -c SpiDevice.cpp
g++ -Wall -std=c++11 -o spi_test spi_main.o SpiDevice.o
make: warning: Clock skew detected. Your build may be incomplete.
root@orangepizerolts:~/SPI_test# ls
Makefile SpiDevice.cpp SpiDevice.h SpiDevice.o spi_main.cpp spi_main.o spi_test
root@orangepizerolts:~/SPI_test# ./spi_test
Received data: 0xaa 0xbb 0xcc
Received data: 0xaa 0xbb 0xcc
Received data: 0xaa 0xbb 0xcc
Received data: 0xaa 0xbb 0xcc
Received data: 0xaa 0xbb 0xcc
Received data: 0x0 0x0 0x0
Received data: 0x0 0x0 0x0
Received data: 0x0 0x0 0x0
Received data: 0x0 0x0 0x0
Received data: 0x0 0x0 0x0
Received data: 0x0 0x0 0x0
Received data: 0xaa 0xbb 0xcc
Received data: 0xaa 0xbb 0xcc
Received data: 0xaa 0xbb 0xcc
Received data: 0xaa 0xbb 0xcc
^C
root@orangepizerolts:~/SPI_test#
默认发送aa bb cc,当mosi和miso短接后,接收到的数据也是aa bb cc,中间拔掉一端后无法正常接收到aa bb cc。
2、uart
//1、系统默认关闭了uart1,uart2,打开该文件:
vi /boot/orangepiEnv.txt
//2、输入以下内容:
overlays=uart1 uart2
//3、保存后重启
reboot
a) 26pin 中的 uart1 对应/dev/ttyS1 b) 26pin 中的 uart2 对应/dev/ttyS2