Skip to content

Commit a0b2f48

Browse files
committed
docs/machine.SPI: Bring up to date with Hardware API, make vendor-neutral.
1 parent c8d3158 commit a0b2f48

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

docs/library/machine.SPI.rst

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
.. currentmodule:: machine
22

3-
class SPI -- a master-driven serial protocol
4-
============================================
3+
class SPI -- a Serial Peripheral Interface bus protocol
4+
=======================================================
55

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).
811

912
.. only:: port_wipy
1013

@@ -21,31 +24,37 @@ there are 3 lines: SCK, MOSI, MISO.
2124
Constructors
2225
------------
2326

24-
.. only:: port_wipy
27+
.. class:: SPI(id, ...)
2528

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).
2733

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.
3338

3439
Methods
3540
-------
3641

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)
3843

3944
Initialise the SPI bus with the given parameters:
4045

41-
- ``mode`` must be ``SPI.MASTER``.
4246
- ``baudrate`` is the SCK clock rate.
4347
- ``polarity`` can be 0 or 1, and is the level the idle clock line sits at.
4448
- ``phase`` can be 0 or 1 to sample data on the first or second clock edge
4549
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).
4958
5059
.. method:: SPI.deinit()
5160
@@ -71,7 +80,7 @@ Methods
7180

7281
Write from ``write_buf`` and read into ``read_buf``. Both buffers must have the
7382
same length.
74-
Returns the number of bytes written
83+
Returns the number of bytes written.
7584

7685
Constants
7786
---------
@@ -83,3 +92,7 @@ Constants
8392
.. data:: SPI.MSB
8493

8594
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

Comments
 (0)