SPI — 串行外设接口总线协议(master side)

class SPI(...)

使用示例::(python)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# coding=utf-8
# This is a sample Python script.
from driver import SPI

print("-------------------spi test--------------------")
spi = SPI()
spi.open("SPI0")
readBuf = bytearray(3)
writeBuf = bytearray([0x9f])
print(writeBuf)
print(readBuf)
value = spi.sendRecv(writeBuf, readBuf)
print(value)
print(writeBuf)
print(readBuf)
spi.close()
print("-------------------spi test--------------------")

配置信息::(json)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# coding=utf-8
# This is a sample cjson file.
{
  "version": "1.0.0",
  "io": {
    "SPI0": {
      "type": "SPI",
      "port": 0,
      "mode": "master",
      "freq": 2000000
    }
  },
  "debugLevel": "DEBUG"
}

操作函数

open(jsonConfigPath, type)

打开SPI并根据json文件配置SPI实例

write(dataBuffer)

通过SPI发送数据,该函数为阻塞函数,SPI发送完成后才会返回

read(dataBuffer)

读取指定bytes的SPI数据,该函数为阻塞函数,读取到指定bytes的数据后才会返回

sendRecv(writeDataBuffer, readDataBuffer)

通过SPI发送数据阻塞发送数据,发送完后,再阻塞读取指定bytes的数据

close()

关闭SPI实例