Problem with two chained shift register (wrong output)

Dear Arduino community,

I'm currently struggle getting two chained shifting registers (SN74HC595) to work with the Arduino Nano 33 IoT. Everything works fine with an Arduino Nano Every, Nano ESP32 and Uno R3.
Using a simple code example that activate/deactive each output, one by one, so only one output of the shift register is active at the same time.
I get some unexpected behaviour, when talking to the first shift register everything seems to work fine but as soon as I trigger the second one the problems start to begin. Problems are, two ore more outputs are active at the same time or no output is active (but should be). The output is inconsistent, I can not see a pattern.
When replacing SPI with the ShiftOut()-function the exact same problem occur.

Here is the code example I'm using. As described above it just activate/deactivate each output, one after another.

code example
#include <SPI.h>


int tDelay = 500;
int latchPin = 10;

uint16_t leds = 0;

void updateShiftRegister(uint16_t number){
    digitalWrite(latchPin, LOW);
    SPI.transfer(highByte(number));
    SPI.transfer(lowByte(number));
    digitalWrite(latchPin, HIGH);
}

void setup(){
    Serial.begin(115200);
    pinMode(latchPin, OUTPUT);
    SPI.begin();
    updateShiftRegister(0);
}

void loop(){
    leds = 0;
    updateShiftRegister(65535);
    delay(tDelay);
    updateShiftRegister(leds);
    for (int i = 0; i < 16; i++){
        bitSet(leds, i);
        Serial.println(leds);
        updateShiftRegister(leds);
        delay(tDelay);
        bitClear(leds, i);
    }
}

Here's a simplified schematic. I haven't drawn wires for Vcc and GND. I have an external power source (5V) connected to Vcc of each shift register.
OE is connected to GND.
SRCLR is connected to Vcc.
A LED is connected to every output so I can visually see what happens.

schematic

updated schematic

As mentioned above the output follows no real pattern (in my opinion) but there are some cases that seems to happen very often. I therefore created this little table, it may be helpful?! Normally only the output that shares the same value as i should be active.
For me the most interesting part is the first entry in the table. Because when i == 7 I'm sending 10000000b to the first shift register and 00000000b to the second one. So why is output 8 (first output of the second shift register) active?

value table
i active outputs
7 7, 8
9 9, 10
11 11, 12
13 13, 14
14 14, 15
15 no output active

I have no ideas (and skill) to figure out what is happening here. Since the code works fine with three other boards I may think it has something to do with the Arduino Nano 33 IoT. Is there something special about this board? Does my board malfunction?

Thanks for any help and ideas. Have a nice evening.

Well compared to what other board? The nano 33 IoT board is 3V3 which is not a big enough signal to guarantee to drive a 5V shift register.

In your "simplified" circuit diagram, (I would say it is incomplete) I don't see how you address the different shift registers,which might explain:-

1 Like

sketch works as expected.

and with shiftOut() same success:

const int tDelay = 500;
const  byte latchPin = 10;
const  byte SerPin = 11;
const  byte ClockPin = 13;

void updateShiftRegister(uint16_t number) {
  digitalWrite(latchPin, LOW);
  shiftOut(SerPin,ClockPin,MSBFIRST,highByte(number));
  shiftOut(SerPin,ClockPin,MSBFIRST,lowByte(number));
  digitalWrite(latchPin, HIGH);
}

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(SerPin, OUTPUT);
  pinMode(ClockPin, OUTPUT);
}

void loop() {
  uint16_t leds = 1;
  updateShiftRegister(65535);
  delay(tDelay);
  for (int i = 0; i < 16; i++) {
    updateShiftRegister(leds);
    delay(tDelay);
    leds <<= 1;
  }
}

1. The above is well supported by the data sheets (Fig-1) though marginal.


Figure-1:

2. OP is advised to use level shifter (Fig-2) among Nano 33 IoT, DS, SH_CP, ST-CP for which he requires a 5V supply at the High Side of the level shifter. Should work; if not, efforts are to be made to find the problem.
levelShifterPic
Figure-2:

No, VIH = 0.7*VCC = 3.5 V when VCC = 5 V.

The first chip is getting 3.3 V on all inputs and just happens to work, but the second one is getting 5 V from the first chip on SER, which might cause the problem.

EDIT
I was looking at the Texas Instruments datasheet, it does not have a 'typical' or 'nominal' value for VIH, just a minimum value.

I think you are missing something with that statement. VCC can't be 3.5V when VCC is 5V.

What else would you expect it to have for an High level input to be recognised?

The other boards are a Nano Every, Nano ESP32 and Uno R3. Yes I know that the IoT is a 3V board. As stated in OP I'm using an external 5V power source to drive the shift register. I used this external power source for all four boards and never used the onboard 5V (in case it existed).

Sorry, I have updated the schematic and drawn some more GND and Vcc lines.

updated schematic

I do not understand what you mean by

I don't see how you address the different shift registers

Qh' is connected to SER of the next shift register. Both shares the same RCLK and SRCLK. That should be all? Even the documentation tells me to connect it like that to daisy chain shift registers.

daisy chaining explained in docs

Read again more carefully.
It says VIH = 3.5 V when VCC = 5 V..

Thanks for testing this but it seems like you were using an Arduino Nano in that simulation? As stated in OP the code runs fine for me on a Arduino Nano, Nano ESP32 and Uno R3. It's just the Nano 33 IoT that is not working properly.

As an experiment, what happens if you change the 5V supply to the 74HC595s to 3.3V from the Arduino Nano 33 IoT?
This would show whether or not the problem is caused, when operating on 5V, by the GPIO output of the Arduino Nano 33 IoT not being high enough to reliably cause the 74HC595 to see a logic 1. I know you tried another 3.3V Arduino that worked, but maybe it had slightly different GPIO high voltage

No! The SCLK (ST_CP) must be seperated - meaning each HC595 will have its own ST_CP clock line to latch the data at the input of the 3-state output buffer. Fig-1 (a tested Min-Sec Down Counter) may help to understand the functioning of two 74HC595 in casecade operation.


Figure-1:

All your problems will be solved if you use 74HCT595

The VIH and VIL specifications of both 74HC595 and 74HCT595 are exactly nearly the same except that HCT596 is CMOS design. Then how HCT595 is going to solve OP's problem? //edit

Really?

What do you think the C in HC(T) means?

Right!
'C' for CMOS , 'T' for TTL-compatibility and H for high-speed.

Thank you! I am editing my post #13.

When I have asked Google for 74HCT595 data sheets, I have thought that I have got the right data sheets. Now, I see that Google has supplied me the data sheets fo 74HC595. This is the cause of my errors!

I have a .pdf file of the common 74HCT chips available from Mouser as I use them almost exclusively for through hole logic.
74HCT Logic.pdf (94.1 KB)

Thanks for your suggestion.
I did tried that and it worked without any problems when using the 3.3V. I observed it for 30 minutes without any errors. I then turned on the 5V power source again and the problem returned instantly.

It seems like your guess is correct. Since I'm an absolute beginner I have no clue how to solve this problem. In my final application I need the 5V power source to drive some other ICs so it would be no solution for me to switch to a 3.3V power source.
Is there any way to handle this?

I do not want to say that you are incorrect but mulitple sources says different things, for example this document from TI https://www.ti.com/lit/an/scea117/scea117.pdf

Paragraph 1.6 - Daisy-Chain Two Shift Register

Typically, all of the clock signals will be shorted together, although they can be separated for unique cases.

I have seen some threads here where users need to seperate each latch pin but in my case I just want to use the registers the normal way (and not in an unique way).

If I follow your approach further. Let's say I want to use 30 chained registers. Do I need 30 latch pins?
I also wonder how the code would look like then. Like this?

void updateShiftRegister(uint16_t number){
    digitalWrite(latchPin1, LOW);
    digitalWrite(latchPin2, LOW);
    SPI.transfer(highByte(number));
    SPI.transfer(lowByte(number));
    digitalWrite(latchPin2, HIGH);
    digitalWrite(latchPin1, HIGH);
}

So everytime I pull latch pin 1 down I need to pull latch pin 2 down, too and vice versa. So my understanding would be that I can short them together. Or do I miss something?

Thanks for suggesting that. Could you please explain to me why they should work? Sadly I do not understand very much of the data sheet.
This chip seems to be unavailable in my country so I have to import them. I would like to know why before I buy them.

@EmilyJane: since you metioned the same chip I would like to ask you the same question.

Thanks a lot in advance.

Do you have a schematic, block diagram, or IC list for your final application? Without more information suggestions for solutions may not be a good fit.