simple shift registor problem drivng me bongers!

okay got a tpic6b595 wired on a breadboard to turn on leds.
decoupling cap included, seperate resistor of each led

trying to use the SPI method.

Arduino tpic6b595
P13 12
p12 3
p10 13
8 vcc
9 gnd

here is the sketch

// SPI commands will be used to send the data out


#include <SPI.h> // bring in SPI library

#define SS  10 // output latch for cathodes shift register.  Pin D10 needs to be an output for SPI.

byte dataArray[]= {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};  // load up some initial data
// dataArray[0] = B00000001
// dataArray[1] = B00000010
// dataArray[2] = B00000100
// dataArray[3] = B00001000
// dataArray[4] = B00010000
// dataArray[5] = B00100000
// dataArray[6] = B01000000
// dataArray[7] = B10000000


int x=0;



void setup()
  {

    pinMode (SS, OUTPUT);

    SPI.begin();  // commits 11,12,13 for hardware SPI transfer. Make sure shift registers have 0.1uF/100nF on their VCC pins to ground.
    SPI.setBitOrder(LSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV8);
    SPI.setDataMode(SPI_MODE1);



  }

void loop()
{

  // turn off leds
  digitalWrite (SS, LOW);
  SPI.transfer(0); 
  digitalWrite (SS, HIGH);
  delay(1000);


  for(x=0;x<7;x++)
   {
     // turn on one led, all others off for apox. half a second
     digitalWrite (SS, LOW);
     SPI.transfer(dataArray[x]); 
     digitalWrite (SS, HIGH);
     delay(500);
   
   }

} // end void loop

Now its turning on and off leds in groups, turning on one after the other, sequence ever other one, just seems to do whatever it feels like except what I want it to do. And this WITHOUT changing any of the code first and upload it.

What am I doing wrong???
I tryed changing SPI mode, Clock rate, change code to read just ONE dataArray cell over and over, change delays, wiggleing wires , nothing seems to work ....

HELP!!!

want to add the lines from arduino to breadboard are apox. 12ins long.
power and gnd come from arduino. power stable at 5.0v to breadboard....

Shift registers are notoriously noisy...have you decoupled the power supply close to the pins?

I would also shorten any wiring to as short as possible, after all wires make great aerials...... :grin:

got decoupling caps right next to power coming in breadboard and going across pin 2 and pin 19 on chip .1uF

Do you have OE connected to Gnd, and MSTRCLR connected to +5?

I don't if this order matters:

// SPI.begin(); // commits 11,12,13 for hardware SPI transfer. Make sure shift registers have 0.1uF/100nF on their VCC pins to ground.
SPI.setBitOrder(LSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV8);
SPI.setDataMode(SPI_MODE1);
// maybe SPI.begin goes here?
// I never use the above, the default settings have worked for me.
SPI.begin(); // commits 11,12,13 for hardware SPI transfer. Make sure shift registers have 0.1uF/100nF on their VCC pins to ground.

Your wiring is also be an issue:
Arduino tpic6b595
D13 (SCK) 13 (SRCK) - shift register clock
D12 (MISO) not connected
D11 (MOSI) 3 (serial data in)
D10 (SS) 12 (RCK) - output register clock
9 (G/ or OE/), needs to be low to enable output drivers
8 (SRCLR/ or MSTCLR/), needs to be high, otherwise outputs are cleared

everything wired up right.
code seems to work. I put in some serial monitor stuff and its cycling through correctly(reading through array and what is suppose to be in each cell is there)

Now just blinks all on then all off....

Does anybody have problems with these "solderless" breadboards using 22gauge hookup wire??

okay I've rewritten the code using shiftout() and guess what it works!
Now I'll being going back to SPI and try it again. If it acts screwy again then it must be something to do with the internal arduino chip hardware implemention...

If it acts screwy again then it must be something to do with the internal arduino chip hardware implemention...

Doubtful - it's usually operator error.

Ran into that just today - I inherited some code (a revision of an example I had supplied) for SPI.transfers to four uniqiue shift registers.
Tweaked a part to move slave_select from one pin to another.
Took me quite a while to realize that original writer had used #s in void setup for pinMode assignments, and also had used #s again elsewhere in void setup to turn on the internal pullups.
Once I changed all the #s to be the signal name I had assigned to the pin, things started playing nice,

moved the wiring back on the uno for SPI reloaded the scketch and now its working... :slight_smile: Its now time to play with the code while I'm waiting for a shipment of parts to build the more permenent boards.....

yeaaa