forked from devttys0/libmpsse
-
Notifications
You must be signed in to change notification settings - Fork 25
/
README.SPI
39 lines (27 loc) · 1.71 KB
/
README.SPI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Libmpsse supports configuring FTDI chips to operate as SPI master devices in order to communicate with SPI slave devices.
There are four standard modes that an SPI bus can support (modes 0 and 3 are most common):
1) Mode 0 (SPI0)
2) Mode 1 (SPI1)
3) Mode 2 (SPI2)
4) Mode 3 (SPI3)
While libmpsse fully supports SPI modes 0 and 2, due to the limitations of the FTDI chips modes 1 and 3 will only work with
SPI chips that support on the fly instruction decoding. Certian chips, particularly those that support daisy chaining, will
typically not function properly with libmpsse in SPI modes 1 and 3.
When initializing libmpsse, you must specify:
1) The SPI mode to use
2) The SPI clock frequency
3) The data transfer endianess (MSB first or LSB first - MSB is most common)
After initialization, you can communicate with any connected SPI slave device. A standard SPI transaction involves:
1) Sending a start condition to indicate the beginning of a transaction
2) Reading / writing data to and from the slave device
3) Sending a stop condition to indicate the end of a transaction
By default, CS idles high; you may specify an idle-low CS state with the SetCSIdle method:
SetCSIdle(0)
Finally, once you are finished talking to your SPI slave device you must close the connection to the FTDI chip.
The following is a simple example of using SPI in Python:
spi = MPSSE(SPI0, THIRTY_MHZ, MSB) # Use SPI mode 0 with a 30MHz clock, send/receive data MSB first
spi.Start() # Bring chip-select low
spi.Write("\x03\x00\x00\x00") # Write 4 bytes of data to the slave device
data = spi.Read(256) # Read 256 bytes back from the slave device
spi.Stop() # Bring chip-select high
spi.Close() # Close connection to the FTDI chip