1
1
.. currentmodule :: machine
2
2
3
- class SPI -- a master-driven serial protocol
4
- ============================================
3
+ class SPI -- a Serial Peripheral Interface bus protocol
4
+ =======================================================
5
5
6
- SPI is a serial protocol that is driven by a master. At the physical level
7
- there are 3 lines: SCK, MOSI, MISO.
6
+ SPI is a serial protocol that is driven by a master. At the physical level,
7
+ bus consistens of 3 lines: SCK, MOSI, MISO. Multiple devices can share the
8
+ same bus. Each device should have a separate, 4th signal, SS (Slave Select),
9
+ to select a particualr device on a bus with which communication takes place.
10
+ Management of an SS signal should happen in user code (via machine.Pin class).
8
11
9
12
.. only :: port_wipy
10
13
@@ -21,31 +24,37 @@ there are 3 lines: SCK, MOSI, MISO.
21
24
Constructors
22
25
------------
23
26
24
- .. only :: port_wipy
27
+ .. class :: SPI(id, ...)
25
28
26
- .. class :: SPI(id, ...)
29
+ Construct an SPI object on the given bus, ``id ``. Values of ``id `` depend
30
+ on a particular port and its hardware. Values 0, 1, etc. are commonly used
31
+ to select hardware SPI block #0, #1, etc. Value -1 can be used for
32
+ bitbanging (software) implementation of SPI (if supported by a port).
27
33
28
- Construct an SPI object on the given bus. ``id `` can be only 0.
29
- With no additional parameters, the SPI object is created but not
30
- initialised (it has the settings from the last initialisation of
31
- the bus, if any). If extra arguments are given, the bus is initialised.
32
- See ``init `` for parameters of initialisation.
34
+ With no additional parameters, the SPI object is created but not
35
+ initialised (it has the settings from the last initialisation of
36
+ the bus, if any). If extra arguments are given, the bus is initialised.
37
+ See ``init `` for parameters of initialisation.
33
38
34
39
Methods
35
40
-------
36
41
37
- .. method :: SPI.init(mode, baudrate=1000000, \*, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=(CLK, MOSI, MISO))
42
+ .. method :: SPI.init(baudrate=1000000, \*, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=(CLK, MOSI, MISO), sck=None, mosi=None, miso=None )
38
43
39
44
Initialise the SPI bus with the given parameters:
40
45
41
- - ``mode `` must be ``SPI.MASTER ``.
42
46
- ``baudrate `` is the SCK clock rate.
43
47
- ``polarity `` can be 0 or 1, and is the level the idle clock line sits at.
44
48
- ``phase `` can be 0 or 1 to sample data on the first or second clock edge
45
49
respectively.
46
- - ``bits `` is the width of each transfer, accepted values are 8, 16 and 32.
47
- - ``firstbit `` can be ``SPI.MSB `` only.
48
- - ``pins `` is an optional tuple with the pins to assign to the SPI bus.
50
+ - ``bits `` is the width in bits of each transfer. Only 8 of is guaranteed to be supported by all hardware.
51
+ - ``firstbit `` can be ``SPI.MSB `` or ``SPI.LSB ``.
52
+ - ``pins `` is an optional tuple with the pins to assign to the SPI bus (deprecated, only for WiPy).
53
+ - ``sck ``, ``mosi ``, ``miso `` are pins (machine.Pin) objects to use for bus signals. For most
54
+ hardware SPI blocks (as selected by ``id `` parameter to the constructore), pins are fixed
55
+ and cannot be changed. In some cases, hardware blocks allow 2-3 alterbative pin sets for
56
+ a hardware SPI block. Arbitrary pin assignments are possible only for a bitbanging SPI driver
57
+ (``id``=-1).
49
58
50
59
.. method:: SPI.deinit()
51
60
@@ -71,7 +80,7 @@ Methods
71
80
72
81
Write from ``write_buf `` and read into ``read_buf ``. Both buffers must have the
73
82
same length.
74
- Returns the number of bytes written
83
+ Returns the number of bytes written.
75
84
76
85
Constants
77
86
---------
@@ -83,3 +92,7 @@ Constants
83
92
.. data :: SPI.MSB
84
93
85
94
set the first bit to be the most significant bit
95
+
96
+ .. data :: SPI.LSB
97
+
98
+ set the first bit to be the least significant bit
0 commit comments