Page 1 of 1

SPI slave devices

Posted: Tue Feb 05, 2013 12:24 pm
by RenKang
Hi guys,

I am in the process of considering UART or SPI for my Pi. According to this article:

https://projects.drogon.net/understandi ... pberry-pi/

Gordon says "The Raspberry Pi only implements master mode at this time and has 2 chip-select pins, so can control 2 SPI devices." But I am just thinking can we turn those 8 extra GPIOs as chip-select pins? So that I can control up to 7 devices. Maybe?

Also I am wondering which one is more convenient for Pi's communication, programming wise, UART or SPI?

Cheers,
Ren

Re: SPI slave devices

Posted: Tue Feb 05, 2013 12:50 pm
by bgreat
Using a demultiplexer chip (74HC138 or '139 or '154), it is a simple task to add additional SPI chip selects. To maintain the SPI CE timing, you connect your GPIO lines to the address inputs, the SPI CEx line to an input, and use the outputs as your new SPI select lines.

1 '139 plus 2 GPIO, 2 SPI CEx -> 8 SPI chip selects
2 '138 plus 3 GPIO, 2 SPI CEx -> 16 SPI chip selects
2 '154 plus 4 GPIO, 2 SPI CEx -> 32 SPI chip selects

Here is a link to the Fairchild 74VHC138 to get you started.

Enjoy!
Bill

Edit: Fixed my typos's :D

Re: SPI slave devices

Posted: Tue Feb 05, 2013 1:53 pm
by RenKang
Thanks for your advice Bill. That's sounds great for more chip selections. But since in my case I just have 5 slave chips to control, I think if I can use GPIOs on my Pi as CE pins, shouldn't it be plenty and more straight forward to just use Pi's GPIO to control 5 chips?

Supposedly UART would use same amount of pins. Which one do you think would be more compatible with Pi, UART or SPI?

Cheers,
Ren
bgreat wrote:Using a demultiplexer chip (74HC138 or '139 or '154), it is a simple task to add additional SPI chip selects. To maintain the SPI CE timing, you connect your GPIO lines to the address inputs, the SPI CEx line to an input, and use the outputs as your new SPI select lines.

1 '139 plus 2 GPIO, 2 SPI CEx -> 8 SPI chip selects
2 '138 plus 3 GPIO, 2 SPI CEx -> 16 SPI chip selects
2 '154 plus 4 GPIO, 2 SPI CEx -> 32 SPI chip selects

Here is a link to the Fairchild 74VHC138 to get you started.

Enjoy!
Bill

Edit: Fixed my typos's :D

Re: SPI slave devices

Posted: Tue Feb 05, 2013 3:06 pm
by bgreat
I have had great success using SPI on the Pi via C/C++ and Python with Raspberry Pi spidev interface. Also, the SPI interface synchronous clock interface can be more reliable at higher speeds.

The GPIO's can be used as direct chip selects via your own code. The only issue would be that you need to activate / deactivate the select in your code before / after calling the SPI driver. Using half of a '139 with 2 GPIO pins plus one SPI CEx allows for 4 SPI devices on a SPI CEx. Add in the other SPI CEx and you get 5 devices with 2 GPIO pins, plus 2 SPI CEx pins. :) Fun!

Not much for complication and saves one program step as the activate / deactivate are controlled by the hardware. You will only need to select the device. This also will make certain that only one device can be active and drive your input.

Enjoy!
Bill

Re: SPI slave devices

Posted: Tue Feb 26, 2013 2:29 am
by venksntu
bgreat wrote:I have had great success using SPI on the Pi via C/C++ and Python with Raspberry Pi spidev interface. Also, the SPI interface synchronous clock interface can be more reliable at higher speeds.
What is ur slave is it raspberry pi?

Re: SPI slave devices

Posted: Tue Feb 26, 2013 9:23 am
by Arjan
Hi,

For an example with the 74HC139 see also http://www.raspberrypi.org/phpBB3/viewt ... 15#p267915

Arjan

Re: SPI slave devices

Posted: Tue Feb 26, 2013 9:38 pm
by bgreat
The Raspberry Pi does not have hardware support to be used as a SPI slave device.

I have been experimenting with SPI LCD displays, ADCs, DACs, and port expanders. I have also done some work with high speed communication with Stellaris processors over SPI.

Enjoy!
Bill