Tpic6b595 daisy chain does not work

Hello:
I have two Tpic6b595 connected in daisy chain like the image, I have put only four leds to try, Tpic1: leds in Drain0, Drain 1. Tpic2: leds in Drain 0 Drain 1.

The problem is that four leds lights on in 0,1,2 counter and lights two leds at the same time (counter 1), I need to turn on leds individually and in its corresponding position, in this case must light on 0,1 on Tpic1 and 8,9 and Tpic2. It seems that the second Tpic is not working properly.

Can you help me please?

I have using Arduino Mega

and this is the code:

//Pin connected to latch pin 
const int latchPin = 9;
//Pin connected to clock pin 
const int clockPin = 8;
////Pin connected to Data in 
const int dataPin = 7;

int counter = 0;
int numLedsInUse = 16;

void setup() {
 //set pins to output because they are addressed in the main loop
 pinMode(latchPin, OUTPUT);
 pinMode(dataPin, OUTPUT);  
 pinMode(clockPin, OUTPUT);
 Serial.begin(9600);
 Serial.println("*");
 
 // delay a little and then set
 delay(100); 
}

void loop() {
 // Display LED's running
 if( counter >= (numLedsInUse-1) ){
   counter = 0;
 } else {
   counter++;
 }

 Serial.println(counter);
 // write to the shift register with the correct bit set high:
 registerWrite(counter, HIGH);
 delay( 500 );
}

// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
 // the bits you want to send
 byte bitsToSend0 = 0;
 // write number as bits
 bitWrite(bitsToSend0, whichPin, whichState);

 // turn off the output so the pins don't light up
 // while you're shifting bits:
 digitalWrite(latchPin, LOW);
 
 // shift the bits out
 shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);

 // turn on the output so the LEDs can light up:
 digitalWrite(latchPin, HIGH);
}

You have two registers chained, which is a total of 16 bits. Your code only sends 8 bits...

Also, these comments are not correct (but they are not the cause of your problem):

  // turn off the output so the pins don't light up
 // while you're shifting bits:
...
 // turn on the output so the LEDs can light up:
...

You should have 0.1uF ceramic bypass caps on each tpic chip.

Yes, I have put ceramic caps.
Can you tell me please, how to send more bits even for three more Tpic6b595?
I don't know how to do it.

Many thanks

Just have more shift out statements one after the other, one for each shift register.

OK, I will be kind and put you out of your misery.

Your code appears rather addled, but the prime concern is that "shiftOut" sends one byte at a time to the serial registers. If you call it once, it will send that byte to the first shift register - and whatever was in the first shift register will move on to the second. To update two shift registers, you must first arm the latch, then shiftOut the byte for the second latch, then shiftOut the byte for the first latch (because the other will have shifted into the second latch when you do this), then set the latch.

You will have to set up two bytes to shiftOut separately, one after the other.

And extend the process for three or more.

I don't understand you very well. Have you any example please?

I am newbie with this.

many thanks

Did you write that code yourself or did you find it and have no idea what it does?

I found that code in Internet. I don't know very well how it is work.

Ok time to learn how they work and how they interact with code start here https://www.arduino.cc/en/Tutorial/ShiftOut