Go Down

Topic: Trouble shooting TPIC6B595N (Read 860 times) previous topic - next topic

shiznatix

Feb 23, 2013, 01:23 am Last Edit: Feb 23, 2013, 01:27 am by shiznatix Reason: 1
Edit: I must preface this by saying that I am very very new to these things and have never used a shift register before. I am just trying to get a basic situation working so I can study it further to understand what I am doing.

I am trying to get 8 LEDs to be controlled through the shift register TPIC6B595N, datasheet here:
www.sparkfun.com/datasheets/IC/TPIC6B595.pdf

My problem is that I can't get any lights to light up at all.

I have tried following the tutorials and posts here and here:
http://flashgamer.com/arduino/comments/arduino-controlling-24-leds-with-shift-registers
http://arduino.cc/forum/index.php?topic=50529.0

I have attached the Fritzing file and PNG of my project. Sorry, the red box represents the shift register with the notch on the casing being on the far left side (I couldn't figure out how to create your own component). The oddly placed LED is just there to show that the board is powered and working at a minimal level.

I have tried all of the source code on both of the tutorials / posts to no avail. All lights always stay turned off. To show where I left off trying, my code is as follows at the moment:
Code: [Select]
/*
Shift Register Example
for TPIC6B595 shift register by Jens C Brynildsen

This sketch turns reads serial input and uses it to set the pins
of a TPIC6B595 shift register.

Hardware:
* TPIC6B595 shift register attached to pins 7, 8, 11 and 12 of the Arduino,
as detailed below.
* LEDs attached to each of the outputs of the shift register

Based on the example created 23 Mar 2010 by Tom Igoe

10 = register clock / latch pin (RCK)
11 = shift register clear (SRCLR)
8 = serial in (SER IN)
5 = shift register clock(SRCK)
*/

//Pin to clear the register
//const int clearPin = 7;
const int clearPin = 10;
//Pin connected to latch pin (ST_CP) of 74HC595
//const int latchPin = 8;
const int latchPin = 11;
//Pin connected to clock pin (SH_CP) of 74HC595
//const int clockPin = 12;
const int clockPin = 5;
////Pin connected to Data in (DS) of 74HC595
//const int dataPin = 11;
const int dataPin = 8;

int counter = 0;
int numLedsInUse = 24;

void setup() {
 //set pins to output because they are addressed in the main loop
 pinMode(clearPin, OUTPUT);
 pinMode(latchPin, OUTPUT);
 pinMode(dataPin, OUTPUT);  
 pinMode(clockPin, OUTPUT);
 Serial.begin(9600);
 Serial.println("*");
 
 // delay a little and then set
 delay(10);
 // Always start by sentting SRCLR high
 digitalWrite( clearPin, HIGH);
}

void loop() {
 // Display LED's running
 if( counter >= (numLedsInUse-1) ){
   counter = 0;
 } else {
   counter++;
 }
 
 // write to the shift register with the correct bit set high:
 registerWrite(counter, HIGH);
 delay( 10 );
}

// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
 // the bits you want to send
 byte bitsToSend0 = 0;
 byte bitsToSend1 = 0;
 byte bitsToSend2 = 0;

 // turn off the output so the pins don't light up
 // while you're shifting bits:
 digitalWrite(latchPin, LOW);
 
 // Set bit pattern
 bitWrite(bitsToSend0, whichPin, whichState);
 if( whichPin > 7 ){
   bitWrite(bitsToSend1, whichPin-8, whichState);
 }
 if( whichPin > 15 ){
   bitWrite(bitsToSend2, whichPin-16, whichState);
 }
 
 // shift the bits out for all three registers. Note the opposite order.
 shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend2);
 shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend1);
 shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);

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

 
 // debug output
 Serial.print( counter );
 Serial.print( " - " );
 Serial.print( " bitsToSend0 " );
 Serial.print( bitsToSend0, BIN );
 Serial.print( " bitsToSend1 " );
 Serial.print( bitsToSend1, BIN );
 Serial.print( " bitsToSend2 " );
 Serial.println( bitsToSend2, BIN );
 
}

CrossRoads

This shifts out 3 bytes, if you only have 1 shift register the first 2 bytes will never be seen:

  // shift the bits out for all three registers. Note the opposite order.
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend2);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend1);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);

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

Do you have Master Clear pulled High, and OE/ connected to Gnd, or have PWM for controlling brightness?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon

My own 595 tutorial / example:

http://www.gammon.com.au/forum/?id=11518

I don't see where you have Vcc connected to the chip.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

shiznatix

#3
Feb 23, 2013, 03:21 pm Last Edit: Feb 23, 2013, 05:26 pm by shiznatix Reason: 1
Final edit: It seams that the issue was that the shift register wasn't sitting properly in the breadboard. If I hold it down into the board with my fingers then it works perfectly. Super annoying but yep, thats it. Thanks for the help and if anyone knows of a way to keep these in the board better that would be great!

The working code is here:
Code: [Select]
/*
Shift Register Example
for TPIC6B595 shift register by Jens C Brynildsen

This sketch turns reads serial input and uses it to set the pins
of a TPIC6B595 shift register.

Hardware:
* TPIC6B595 shift register attached to pins 7, 8, 11 and 12 of the Arduino,
as detailed below.
* LEDs attached to each of the outputs of the shift register

Based on the example created 23 Mar 2010 by Tom Igoe

10 = register clock / latch pin (RCK)
11 = shift register clear (SRCLR)
8 = serial in (SER IN)
5 = shift register clock(SRCK)
*/

//Pin to clear the register
const int clearPin = 11;
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 10;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 5;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 8;

int counter = 0;
int numLedsInUse = 8;

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

void loop() {
 // Display LED's running
 if( counter >= (numLedsInUse-1) ){
   counter = 0;
 } else {
   counter++;
 }
 
 // write to the shift register with the correct bit set high:
 Serial.print("counter: ");
 Serial.println(counter);
 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);
}


@Nick Gammon - I dont see in your tutorial the basic code for just 1 shift register to light up 1 LED at a time. I fixed the problem with not having the Acc connected, very very silly of me.

Nick Gammon

The nature of shift registers if you have to send 8 bits at once (or more if you connect multiple 595s). So to turn on one LED you have to shift out 8 bits.

As an example:

Code: [Select]

  digitalWrite (LATCH, LOW);
  SPI.transfer (0b00000001);    // turn on one LED
  digitalWrite (LATCH, HIGH);

  delay (1000);

  digitalWrite (LATCH, LOW);
  SPI.transfer (0b00000011);    // turn on a second one
  digitalWrite (LATCH, HIGH);


The second transfer turns on another LED but it also has to send out again the first one.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up