Uno + Ethernet shield (W5100) + SD card + SN74HC165

I have a problem initializing the sd card when these two (the shield + sn74hc165) are connected at the same time.

The setup:

on the sn74hc165 it’s connected like this:

[tt][tt]Arduino [D09] (pin 16)  <-  SH/LD - |1      16| - Vcc                  -> tied to +5 volts
Arduino [D13] (pin 19)  <-    CLK - |2   7  15| - Ce' CLK INH          -> Arduino [D11] (pin 17) - SPI MOSI
                               D4 - |3   4  14| - D3        
                               D5 - |4   H  13| - D2
                               D6 - |5   C  12| - D1
                               D7 - |6   1  11| - D0
          not connected <-    Qh' - |7   6  10| - DS Serial data input -> unused, tied to gnd
                              gnd - |8   5   9| - Qh                   -> Arduino [D12] (pin 18) - SPI MISO[/tt][/tt]

The sn74hc165 is being fed 5V from an external PSU, btw, with its gnd connected to arduino’s.

Since I know the SS is pin 10 on the ethernet shield I chose pin 9 for the shift register chip.
MOSI, MISO and SCK lines are shared with the ethernet shield.
So I should be safe … i.e. by having one separate SS pin for each.

On executing even the simplest cardinfo example it always fails to initialize if I have the sn74h165 connected. Otherwise it always reads the card.

So I’m a bit at a loss for ideas … :smiley:

Any insight as to why it’s happening ?

TIA,
Pedro Doria Meunier

You can't use D4 on the 74HC165. That is the slave select for the SD card.

Thanks for the comment Surfer Tim but D0-D7 on the 74hc165 are the inputs (in this implementation connected to buttons).

What do you mean by "connected to buttons"? As long as you don't try to change D4 with your code, and don't connect anything else to it (no switches, etc), you should be ok. But it is the slave select for the SD card, and it will be changing "on its own" when you access the SD card. Actually, the SD library will be changing D4 as it accesses the SD card. It will be set to OUTPUT and HIGH by the SD.begin(4) function call.

SurferTim:
What do you mean by "connected to buttons"? As long as you don't try to change D4 with your code, and don't connect anything else to it (no switches, etc), you should be ok. But it is the slave select for the SD card, and it will be changing "on its own" when you access the SD card. Actually, the SD library will be changing D4 as it accesses the SD card. It will be set to OUTPUT and HIGH by the SD.begin(4) function call.

Maybe it's the 'D' that's complicating... :wink:
I use the 74hc165 for connecting 6 buttons for driving a menu/other options on the LCD. Using 6 pins on the Arduino for these buttons seemed a great waste of real estate ... :smiley:

To be perfectly clear, nothing is connected to Arduino's pin 4. :wink:

Arduino [D09] (pin 16)  <-  SH/LD - |1      16| - Vcc                  -> tied to +5 volts

Arduino [D13] (pin 19) ←    CLK - |2   7  15| - Ce’ CLK INH         → Arduino [D11] (pin 17) - SPI MOSI
                              D4 - |3   4  14| - D3        
                              D5 - |4   H  13| - D2
                              D6 - |5   C  12| - D1
                              D7 - |6   1  11| - D0
         not connected ←    Qh’ - |7   6  10| - DS Serial data input → unused, tied to gnd
                             gnd - |8   5   9| - Qh                   → Arduino [D12] (pin 18) - SPI MISO

The only thing that is worse than using a regular wiring diagram instead of a schematic diagram is the use of an ASCII wiring diagram.

In this case a real schematic diagram (not what Eagle calls a ‘schematic’) or a plain text listing of the connections would be a lot clearer.

Don

Your schematic is not "perfectly clear", but if nothing is connected to D4, then it is the 74HC165 pin 9 connected to the Arduino D12 that is the problem. On an SPI device, the MISO pin on each SPI slave device must be tri-state. When you disable the device SPI with the slave select pin, pin 9 on the 74HC165 must become hi-z (like an input). It appears by the datasheet it is always an output. That will cause problems, and probably a failure of one of the devices eventually.

SurferTim:
Your schematic is not "perfectly clear", but if nothing is connected to D4, then it is the 74HC165 pin 9 connected to the Arduino D12 that is the problem. On an SPI device, the MISO pin on each SPI slave device must be tri-state. When you disable the device SPI with the slave select pin, pin 9 on the 74HC165 must become hi-z (like an input). It appears by the datasheet it is always an output. That will cause problems, and probably a failure of one of the devices eventually.

Thanks SurferTim! :slight_smile:
I've just tested it and it was in fact 74hc165's pin 9 the culprit... :frowning:
So the verdict is scratch using this chip in conjunction with other spi devices or is there something I can still do?

[EDIT]
Answering myself... :slight_smile:
This provides a solution: http://www.gammon.com.au/forum/?id=11979 "bitBangedSPI" :wink:

Why use SPI on that IC? You know the SPI clock is not a true clock. It doesn't pulse all the time. It only works (pulses) when reading or writing to the SPI bus. Otherwise, it is in a steady state.

Don't use the SPI bus for the 74HC165.