Write and read data from SPI device
data = writeRead(spidevObj,dataIn)
data = writeRead(spidevObj,dataIn,precision)
Create object for an SPI device that is already connected to SPI bus.
microbitObj = microbit('COM3'); spidev1 = device(microbitObj, 'SPIChipSelectPin', P16);
spidev1 = device with properties: SPIChipSelectPin: "P16" SCLPin: "P13" MISOPin: "P14" MOSIPin: "P15"
Use the SPI device object to write data to the SPI device.
writeCmd = bin2dec('0000 0010'); address = [255 0]; data = [250 155]; dataIn = [writeCmd address data]; out = writeRead(spidev1,dataIn)
out = 0 0 0 0 0
Read data from the SPI device.
readCmd = bin2dec('0000 0011'); dataIn = [readCmd address zeros(1,2)]; out = writeRead(spidev1,dataIn)
out = 0 0 0 250 155
spidevObj— SPI device connection
Device connection to a SPI device, specified as a device object, connected to the
SPI bus on the BBC micro:bit board. The SPI device object is created using the
dataIn— Data to write and read
Data to read and write to the SPI device, specified as a scalar or vector. The range of the values in the array is based on the precision.
precision— Data precision
Precision of data to read and write to the SPI device.