More than 2 SPI Chip Enable lines


14 posts
by lukekb » Tue Dec 04, 2012 6:22 pm
I am trying to write to 4 LED modules and each one requires a seperate Chip Enable line. I have it working with 2 displays using the 2 built in Chip Enable lines (CE1 & CE2). Is it possible to repurpose some of the GPIO lines as Chip Enable lines?

From this thread it seems like it is possible: viewtopic.php?f=44&t=22608

It does go into much detail though. Any pointer on what to do?

Since this would have to be tied to the Clock line, would I have to re-write the SPI module? Or could I simply switch a GPIO pin from high to low, write using SPI and then set the GPIO pin high again at the end?
Posts: 14
Joined: Mon Dec 03, 2012 8:51 pm
by Arjan » Tue Dec 04, 2012 7:09 pm
Hi,

An option is to use the 74HC139.
Connect 2 output enabled GPIO pins to A and B.
And a /SPI0_CE line to G.
This will give you 4 SPI /CS lines per SPI0_CE


Hope this helps. Regards, Arjan.
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by techpaul » Tue Dec 04, 2012 9:52 pm
Arjan wrote:An option is to use the 74HC139.
Connect 2 output enabled GPIO pins to A and B.
And a /SPI0_CE line to G.
This will give you 4 SPI /CS lines per SPI0_CE

Hope this helps. Regards, Arjan.
Thats one way or use 74*138 and 3 GPIO lines .

These ways use up GPIO pins heres another way if you dont want to use up so many GPIO pins, uses one more pin well sort of....

Basically we use both Chip Enables, use one to enable writes to one (or more cascaded) 74HC595 to store which device you want enabled (could also drive two at once for output from Pi).

Now comes the 'sneaky' bit, use pull up resistors (I would recommend 8 commoned SIL resistro packs for board space and easier wiring), so that a 1k or higher resistor is on each output of the 74HC595(s). But now we drive the OE pin with the other Chip Enable from the Pi.

This way you can cascade up to however many chip enables you want, easily 32 and even more if you want.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1509
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by Arjan » Wed Dec 05, 2012 1:21 pm
This is a great idea :
Basically we use both Chip Enables, use one to enable writes to one (or more cascaded) 74HC595 to store which device you want enabled (could also drive two at once for output from Pi).


Another option is to use the i2c interface for selecting more SPI CS lines.

I had suggested to use 2 GPIO's lines with the UEXT connector connector in mind. Then alternate pin uses for pin 5 and 6. Using both pin 4 and 5 as GPIO output pins.

The UEXT connector is not available on the RPi, yet. However, you can easily work with it yourself. Or take a look at https://olimex.wordpress.com/2012/11/21/raspberry-pi-gpio-to-breadboard-and-uext-adapter/
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by techpaul » Wed Dec 05, 2012 2:11 pm
Arjan wrote:This is a great idea :
Basically we use both Chip Enables, use one to enable writes to one (or more cascaded) 74HC595 to store which device you want enabled (could also drive two at once for output from Pi).


Another option is to use the i2c interface for selecting more SPI CS lines.

I had suggested to use 2 GPIO's lines with the UEXT connector connector in mind. Then alternate pin uses for pin 5 and 6. Using both pin 4 and 5 as GPIO output pins.

The UEXT connector is not available on the RPi, yet. However, you can easily work with it yourself. Or take a look at https://olimex.wordpress.com/2012/11/21/raspberry-pi-gpio-to-breadboard-and-uext-adapter/


Which is just using more GPIO lines, you are just using GPIO lines that [b]CAN[/b} be used fo I2C, but needs external gating to synchronise with chip enables generally.

UEXT is an Olimex standard and not really relevant
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1509
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by lukekb » Wed Dec 05, 2012 2:32 pm
Wow! Thanks guys, this is great info. I think I am going to keep it simple at first and just order a 74HC139 & 74HC138, since I only have 4 displays to control now and I have lots of extra GPIO lines to use. I remember when Radio Shack used to have ICs in store.

With the 74HC595 would it be possible to select more than one device? When initializing the devices it nice to send the commands to all the device at the same time instead of having to do it serially.

Thanks again for the pointers!
Posts: 14
Joined: Mon Dec 03, 2012 8:51 pm
by Arjan » Wed Dec 05, 2012 2:34 pm
UEXT is an Olimex standard and not really relevant


The UEXT is relevant for creating a more portable extension board.
Luckily we have two SPI /CS lines on the RPi. However, most other ARM systems just have one SPI /CS on the external connector.

Working with a standard (at the time of this writing we have the UEXT only) will create the opportunity to work with a lot of extension boards. Or work with many ARM systems which can use your extension board.
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by techpaul » Wed Dec 05, 2012 3:30 pm
Arjan wrote:
UEXT is an Olimex standard and not really relevant


The UEXT is relevant for creating a more portable extension board.
Only seen it with Olimex boards
Luckily we have two SPI /CS lines on the RPi. However, most other ARM systems just have one SPI /CS on the external connector.

Working with a standard (at the time of this writing we have the UEXT only) will create the opportunity to work with a lot of extension boards. Or work with many ARM systems which can use your extension board.

ARM has very little to with it having worked with many micros of various sizes, and there are many many ARMs out there a lot not even running Linux/Android/other large OS.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1509
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by techpaul » Wed Dec 05, 2012 3:32 pm
lukekb wrote:Wow! Thanks guys, this is great info. I think I am going to keep it simple at first and just order a 74HC139 & 74HC138, since I only have 4 displays to control now and I have lots of extra GPIO lines to use. I remember when Radio Shack used to have ICs in store.
I assume from that you are in USA as I have no other way of knowing
With the 74HC595 would it be possible to select more than one device? When initializing the devices it nice to send the commands to all the device at the same time instead of having to do it serially.

Thanks again for the pointers!

Only useful if SAME data has to be written to two or more devices at once. Like writing 0 to all.

You either do it serially or more long winded ways for parallel on the GPIO, unless you can find a way to write your own driver for byte wide transfer.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1509
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by lukekb » Wed Dec 05, 2012 7:47 pm
techpaul wrote:I assume from that you are in USA as I have no other way of knowing

Yep... just remembering when Radio Shack used to sell more than cell phones

Only useful if SAME data has to be written to two or more devices at once. Like writing 0 to all.


Yep, the initialization commands are the same for all the boards, so it would be great to be able to do them all at once.

Thanks again
Posts: 14
Joined: Mon Dec 03, 2012 8:51 pm
by johndpar » Sat Dec 08, 2012 1:03 pm
Hi all
I've been following this thread with interest.
I like the idea of using spare GPIO lines for additional SPI chip selects, possibly with a 138 decoder to save on pins, but has anyone implemented this in a kernel driver so that SPI connected peripherals can play nicely with the kernel?

e.g. If I have a four UART chips for which there are already kernel drivers available, I'd want to access those chips via the standard tty interface but the kernel needs to know how to operate the chip selects via the HC138 or GPIO pins.

Any ideas?

John
Posts: 6
Joined: Sat Dec 08, 2012 12:56 pm
by lukekb » Thu Feb 14, 2013 3:44 am
I just wanted to thank everyone for the pointers. I got it all working! I put together a quick writeup of what I did here: http://lukeberndt.com/2013/raspberry-pi ... d-via-spi/
And code is here: https://github.com/robotastic/SPI-LED-Print
I am not sure if I wired things up correctly though.

- Should the power for the 74HC139, from the RPi be 3.3v or 5v? Would 5v make the signal to the LED Matrix stronger and allow for a longer ribbon cable connection between them? I went with 3.3v because I wanted to make sure I wouldn't fry any RPi pins.

- Should I connect the unused pins on the 74HC139 to ground? How about some of the unused pins on the connection to the LED Matrixs?

Image
Posts: 14
Joined: Mon Dec 03, 2012 8:51 pm
by Arjan » Thu Feb 14, 2013 10:36 am
Hi,

The best practice is to use a buffer between the RPi and your hardware. When you have write's only to your LED-print, then a 74HC244 could be used.
Also I would recommend to use an external 5 volt power supply. And not using any power from the RPi.

For example
RPi-GPIO-V3.png
RPi-GPIO-V3.png (19.51 KiB) Viewed 2062 times


Hope this helps.
Regards, Arjan
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by technix » Tue Jun 03, 2014 7:04 pm
Use three chips and you get 32 CS's: one PCF8574 8-bit I2C I/O expander, and two 74HC154 4-16 bit decoders. The 8574 allows you to choose two of the 32 to be in the current frame and 74154 decoders is demultiplexers that delivers the CS line. That will be more than enough for you.
Posts: 29
Joined: Sat Jul 13, 2013 4:55 pm