TPIC6A595 Shift Register problems?

All right, so I noticed that the shift register attached to my Arduino isn’t quite working properly.
I tried running this test code:

void loop(){
for(int i = 0; i < 256; i++) {

// Uses SPI to clock in data, then latches to set LED on/off
void writeToRegister(byte data) {
 // digitalWrite(LATCHPIN, LOW);
  digitalWrite(LATCHPIN, LOW);
  digitalWrite(LATCHPIN, HIGH);

The code works fine for i==1 and i==2.
Starting from i==3, it begins to look like B00000101 and starts shifting to the right (eg. i==4 looks like B00001010, etc. bitshift << 1)
Then, it only seems to alternate between B10100101 and B01011010 starting from i=7 all the way up to 255.

SRCLR/serial clear (active low) is connected to 5V, output enable/G (active low) is grounded, SRCK/shift register clock is CLOCKPIN, RCK/register clock/latch is LATCHPIN, and SERIN/serial in is DATAPIN.

Can anyone help with this?

Post wiring and all of the code. Those work the same as the 74HC595 other than wiring. There are several examples on the board.

The other code doesn't touch the register in any way except calling the function writeToRegister(byte data), but here it is anyway (commented some stuff out to try and figure out what was wrong).

I defined constants for the serial in, clock and latch pins, they're in the code.

And I did follow those tutorials, so I don't know what I'm doing wrong...

And I did follow those tutorials,

Which tutorials are those then? Link please.

I hope it is not the tutorial that suggests putting a capacitor on the clock pin, that will over stress your arduino. Have you got a supply decoupling capacitor on your shift register?

Yep remove that 1uF capacitor. Not only is it an arduino killer it will make the thing not work. Instead connect that capacitor across ground and the supply of the chip.

I didn't put a decoupling capacitor between the clock pin and ground, so that's not the problem.

No but if you haven’t put one across the supply it is your problem.

Doesn't seem to make a difference, the shift register still isn't working correctly.

Ok leave it in and I will look at the code. ;)

Take out the highlighted instruction:-
digitalWrite(LATCHPIN, LOW);
digitalWrite(LATCHPIN, HIGH);

Not needed but probably not causing you problems.

The tutorial is for a 74HC595 and you have a TPIC6A595, the pin out is different on those two devices. How have you got it wired up?

SERIN is DATAPIN (pin 10) SRCK is CLOCKPIN (pin 11) RCK is LATCHPIN (pin 12) Vcc and SRCLR are connected to 5V G, PGND, and LGND are connected to GND

And the latch instruction, yeah I tried taking that out a while before and same results.


Odd but it looks like you are only clocking it once per cycle instead of 8 times.

Try changing the latch bit to :-
digitalWrite(LATCHPIN, HIGH);
digitalWrite(LATCHPIN, LOW);

And change
writeToRegister(255 - i);

See if this clocks in all ones to start with or is it still starting off with zeros.

No dice, same problem.
The 255-i bit doesn’t matter at all, actually, as it won’t fix this weird flipflopping during the debugging part of setup() - the part where it flips from displaying byte 165 to byte 90 and vice versa.

the part where it flips from displaying byte 165 to byte 90 and vice versa.

??? That wasn't in the code you posted. There are three sketches on that tutorial page, which one are you following?

It’s at the end of setup(), and I posted about it in the original post.

The problem there is that although the program is sending bytes 0-255, after byte 2, it begins to start acting up, and byte 7 onwards has the flipflopping effect.

If you look at the bytes it is flipping between:- 165 = 0xA5 = b1010 0101 90 = 0x5A = b0101 1010 You will see that it is just doing one shift instead of clocking in 8 bits.

So if you start off by trying to shift in 255 (0xff) and that is it, do you see it appearing as 255 or as 0?

It appears to be 0.

In that case you are not shifting anything at all. I would think you have the clock and the latch enable wiring swapped around.

Yes, that appears to have fixed the problem! Thanks! It also looks like I managed to wire four of the LEDs incorrectly, but that can be fixed with a software fix.