Reuse SS pin of SPI
Reuse SS pin of SPI
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?
Re: Reuse SS pin of SPI
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 before the (possibly several) SPI transfers and 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.
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)
Code: Select all
cs(1)
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.
Re: Reuse SS pin of SPI
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.
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.