SPI pin share SS?

In my application i want to use a SD-Card and an SPI display.

The SD Card is controlled by SD-Library and the Display has a variable for the slave pin

Since i have 0 pins left, i want to share the SS.

My idea was:

  • Connect SD Card
  • Connect Display
  • Variable for SS-Pin (Display) points nowhere (pin number 99)
  • Add "NOT" gate in SS-Pin Display line
  • If the SD library is sending, SS on the Arduino is going high, so SS on the Display goes low (NOT Gate)
  • If SD is not active, SS on Arduino is low, so SS on the Display goes HIGH
  • Display libary can communicate with the display

Is this a good idea? Any other way to do it?

Variable for SS-Pin (Display) points nowhere (pin number 99)

The slave select pin variable is not a pointer. It can't "point nowhere". It can contain a useless value.

Is this a good idea?

It's a wonderful idea. If you can explain how the NOT gate is going to know that the data out of the SPI pins is coming from the display library vs coming from the SD library. When you accept that the only way that the NOT gate can know that is if one pin is high while another is low, you might as well just use those two pins as chip select pins.

sgt_johnny:
Is this a good idea? Any other way to do it?

First things first - are you aware that you can use all the analog pins as digital pins - that might solve the problem?

Assuming you are already using all the analog pins then I wonder if @PaulS is being a bit pessimistic here.

I think what you are suggesting is that the SS Pin should be connected directly to the SD Card device and through an inverter to the Display device. That should allow either one of them to be selected at any one time but it would preclude the option of de-selecting both of them.

It seems worth experimenting with. And you will probably get the answer far quicker with a short test program.

...R

I had to change to Atmega32u4 because of running out of pins.

Its even cheaper since it saves me the FT232 :slight_smile: