Reuse SS pin of SPI

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
mathieu
Posts: 88
Joined: Fri Nov 10, 2017 9:57 pm

Reuse SS pin of SPI

Post by mathieu » Wed Feb 02, 2022 9:07 pm

After I instantiate pyb.SPI(2), is it OK to use pin Y5 (which corresponds to the "/SS" pin of SPI-2) as an output or input Pin using pyb.Pin(), if I don't intend to use it? Or is there some caveat that I should be aware of?

rkompass
Posts: 66
Joined: Fri Sep 17, 2021 8:25 pm

Re: Reuse SS pin of SPI

Post by rkompass » Fri Feb 04, 2022 8:59 pm

YES and No:

I found that the /SS (= /CS) pins are just for superficial completeness part of the SPI pin set.
IMHO they were better exluded from the pinout diagrams as they are no involved in the actual transmission protocols.
This is reflected by the micropython SPI class constructors (see https://docs.micropython.org/en/latest/ ... e.SPI.html):
Neither machine.SPI() nor machine.SoftSPI() have an option for /CS.
Instead it is your responsibility to create the /CS-Pin programmatically "by hand" like in the example given in docs (see above link), and you have to set

Code: Select all

cs(0)
before the (possibly several) SPI transfers and

Code: Select all

cs(1)
afterwards.
So the /CS pins (X5 and Y5 with the Pyboard) are just ordinary pins and you can use any other pin for the /CS functionality.
As you assumed, you can use the /CS pins for ordinary input or output as you like, after you constructed the pin objects accordingly. .

If you have only one peripheral circuit connected to a SPI bus you don't need a /CS pin at all. You can connect the /CS pin of the peripheral to GND and that means any SPI activity (via SCK, MISO, MOSI) sends to or receives from that peripheral.
In the manuals of ADC-chips I wrote drivers for this was explicitly mentioned, so the latter may be not always guaranteed.

rkompass
Posts: 66
Joined: Fri Sep 17, 2021 8:25 pm

Re: Reuse SS pin of SPI

Post by rkompass » Fri Feb 04, 2022 9:03 pm

I forgot to add:
In case you have more than one peripheral connected to a SPI bus you need more /CS pins anyway. You take any other pins for that.

Post Reply