baantonia
Posts: 63
Joined: Fri Feb 06, 2015 2:19 pm

Number of SPI CS lines

Sat Aug 05, 2017 7:04 am

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.

piras77
Posts: 148
Joined: Mon Jun 13, 2016 11:39 am

Re: Number of SPI CS lines

Sat Aug 05, 2017 7:40 am

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.

User avatar
karrika
Posts: 1070
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Number of SPI CS lines

Sat Aug 05, 2017 7:41 am

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.

baantonia
Posts: 63
Joined: Fri Feb 06, 2015 2:19 pm

Re: Number of SPI CS lines

Sat Aug 05, 2017 7:59 am

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.
Last edited by baantonia on Sat Aug 05, 2017 8:13 am, edited 1 time in total.

piras77
Posts: 148
Joined: Mon Jun 13, 2016 11:39 am

Re: Number of SPI CS lines

Sat Aug 05, 2017 8:11 am

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.

baantonia
Posts: 63
Joined: Fri Feb 06, 2015 2:19 pm

Re: Number of SPI CS lines

Sat Aug 05, 2017 8:39 am

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?

Return to “Interfacing (DSI, CSI, I2C, etc.)”