参考:spidev官网
一、安装
下载安装包
tar –zxvf spidev-3.2.tar.gz
cd spidev-3.2
sudo python3 setup.py install
二、api介绍
1.打开spi设备
bus=0
device=0
spi=SPI.SpiDev(bus,device)
打开spi设备, 设备名/dev/spidev-bus.device此处设备为/dev/spi-decv0.0
2. 从SPI设备读取n字节
readbytes(n)
3. 写数据到spi设备
writebytes(list of values)
4. 开始spi传输
xfer(list of values[, speed_hz, delay_usec, bits_per_word])
Performs an SPI transaction. Chip-select should be released and reactivated between blocks.
Delay specifies the delay in usec between blocks.
xfer2(list of values[, speed_hz, delay_usec, bits_per_word])
Performs an SPI transaction. Chip-select should be held active between blocks.