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.
Additional methods for SPI:
data = spi.send_recv(b'1234') # send 4 bytes and receive 4 bytes
buf = bytearray(4)
spi.send_recv(b'1234', buf) # send 4 bytes and receive 4 into buf
spi.send_recv(buf, buf) # send/recv 4 bytes from/to buf
Constructors¶
Methods¶
-
spi.deinit()¶ Turn off the SPI bus.
-
spi.recv(recv, *, timeout=5000)¶ Receive data on the bus:
recvcan be an integer, which is the number of bytes to receive, or a mutable buffer, which will be filled with received bytes.timeoutis the timeout in milliseconds to wait for the receive.
Return value: if
recvis an integer then a new buffer of the bytes received, otherwise the same buffer that was passed in torecv.
-
spi.send(send, *, timeout=5000)¶ Send data on the bus:
sendis the data to send (an integer to send, or a buffer object).timeoutis the timeout in milliseconds to wait for the send.
Return value:
None.
-
spi.send_recv(send, recv=None, *, timeout=5000)¶ Send and receive data on the bus at the same time:
sendis the data to send (an integer to send, or a buffer object).recvis a mutable buffer which will be filled with received bytes. It can be the same assend, or omitted. If omitted, a new buffer will be created.timeoutis the timeout in milliseconds to wait for the receive.
Return value: the buffer with the received bytes.