Page 1 of 1

Number of SPI CS lines

Posted: Sat Aug 05, 2017 7:04 am
by baantonia
I need to control 3 or more SPI slaves and am just confirming that I'm not going up a dead end before I proceed programming a solution.

My question is: Is there any reason why other GPIO pins cannot be used as CS lines as long as at least one of the actual SPI CS are asserted low?

I plan to use a MAX3420E to set up a pi zero as a USB device to transfer 16 24bit ADC values from four MAX11040K chips to a PC. I know the ADC chips can be cascaded, but to make programming simpler I would rather select the ADC chip to be read from, programming would be bare metal written in C. I already have a basic kernel and can access a number of peripherals, including SPI devices.

Re: Number of SPI CS lines

Posted: Sat Aug 05, 2017 7:40 am
by piras77
baantonia wrote:
Sat Aug 05, 2017 7:04 am
My question is: Is there any reason why other GPIO pins cannot be used as CS lines
It is completely up to you whether to use the SPI peripheral's CS signals or not.
Since you are going to use bare metal there shouldn't be any timing issues by controlling arbitrary GPIO pins.

Re: Number of SPI CS lines

Posted: Sat Aug 05, 2017 7:41 am
by karrika
See https://pinout.xyz/pinout/spi#

There is 5 CS lines and 2 SPI devices. So you should be able to control lots of devices.

Many SPI chips also have 3 address pins that allow you to control multiple SPI chips using just one CS line.

Re: Number of SPI CS lines

Posted: Sat Aug 05, 2017 7:59 am
by baantonia
Hmmm.......

Maybe mix and match. Use SPI0 for the USB interface and SPI1 to read from the ADC chips but still using extra GPIO pins for their selection.

Makes sense as it would simplify the configuration and round robin tasks.

Plan to use CS through 4 OR gates along with the GPIO lines for chip selection.

Re: Number of SPI CS lines

Posted: Sat Aug 05, 2017 8:11 am
by piras77
karrika wrote:
Sat Aug 05, 2017 7:41 am
There is 5 CS lines and 2 SPI devices. So you should be able to control lots of devices.
SPI0 can control 2 lines with 3 values (0,1,2). SPI1 can control 3 lines with all 8 values. SPI0 supports DMA, SPI1 not. Well, it's all in the datasheet.

Re: Number of SPI CS lines

Posted: Sat Aug 05, 2017 8:39 am
by baantonia
Or as an alternative, just use SPI0 with its two CS lines and a single MAX11040K and use extra GPIO pins to multiplex the analogue inputs.

Does this sound sensible?