class SPI – a master-driven serial protocol¶
SPI is a serial protocol that is driven by a master. At the physical level there are 3 lines: SCK, MOSI, MISO.
Constructors¶
Methods¶
- 
SPI.init(mode, baudrate=1000000, *, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=(CLK, MOSI, MISO))¶
- Initialise the SPI bus with the given parameters: - modemust be- SPI.MASTER.
- baudrateis the SCK clock rate.
- polaritycan be 0 or 1, and is the level the idle clock line sits at.
- phasecan be 0 or 1 to sample data on the first or second clock edge respectively.
- bitsis the width of each transfer, accepted values are 8, 16 and 32.
- firstbitcan be- SPI.MSBonly.
- pinsis an optional tuple with the pins to assign to the SPI bus.
 
- 
SPI.deinit()¶
- Turn off the SPI bus. 
- 
SPI.write(buf)¶
- Write the data contained in - buf. Returns the number of bytes written.
- 
SPI.read(nbytes, *, write=0x00)¶
- Read the - nbyteswhile writing the data specified by- write. Return the number of bytes read.
- 
SPI.readinto(buf, *, write=0x00)¶
- Read into the buffer specified by - bufwhile writing the data specified by- write. Return the number of bytes read.
- 
SPI.write_readinto(write_buf, read_buf)¶
- Write from - write_bufand read into- read_buf. Both buffers must have the same length. Returns the number of bytes written