SPI transfer to a 74HC595 fails

I started testing the register i bought to build a LED Cube. I use a AT Mega 2560 and try to shift out a byte with SPI but it does fail. All in one it does nothing.

I build this breadboards. (See testing.jpg)

And now trying to shift out a full byte with this code:

#include <SPI.h>// SPI Library used to clock data out to the shift registers

// can use any pin you want to latch the shift registers
// push the to storage register, Pin 12 at IC
#define latch_pin 49
// to shut enable/disable the register. Low enables, Pin 13 at IC
#define blank_pin 48
// used by SPI, must be pin 51 at Mega 2560
#define data_pin 51
// used by SPI, must be 52 at mega 2560, Pin 11 at IC
#define clock_pin 52

byte test;

void setup()
{
  SPI.setBitOrder(MSBFIRST);//Most Significant Bit First
  SPI.setDataMode(SPI_MODE0);// Mode 0 Rising edge of data, keep clock low
  SPI.setClockDivider(SPI_CLOCK_DIV2);//Run the data in at 16MHz/2 - 8MHz
  
  //finally set up the Outputs
  pinMode(latch_pin, OUTPUT);//Latch
  pinMode(data_pin, OUTPUT);//MOSI DATA
  pinMode(clock_pin, OUTPUT);//SPI Clock
  pinMode(blank_pin, OUTPUT);//Output Enable  important to do this last, so LEDs do not flash on boot up
  
  digitalWrite(blank_pin, HIGH);//shut down the led

  test = B11111111;
}

void loop()
{
  //disable pins
  PORTD |= 1<<blank_pin;
  //push the test byte
  SPI.transfer(test);
  
  // shift register to storage register
  PORTD |= 1<<latch_pin;//Latch pin HIGH
  PORTD &= ~(1<<latch_pin);//Latch pin LOW
  //enable pins
  PORTD &= ~(1<<blank_pin);//Blank pin LOW to turn on the LEDs with the new data
}

What have i done wrong?

I am sure ill have to ask some more questions soon but this will be under a different topic. (more electornic).

Thanks alot
Regards,
BennX

Is OE (G) connected to GND?
Is SRCLR connected to +5?
Need a 0.1uF cap from VCC to GND.
The 2nd lead of the LEDs don't appear to be connected to anything.

See << comments >> added in your code:

#include <SPI.h>// SPI Library used to clock data out to the shift registers

// can use any pin you want to latch the shift registers
// push the to storage register, Pin 12 at IC
#define latch_pin 49
// to shut enable/disable the register. Low enables, Pin 13 at IC
#define blank_pin 48
// used by SPI, must be pin 51 at Mega 2560
#define data_pin 51
// used by SPI, must be 52 at mega 2560, Pin 11 at IC
#define clock_pin 52
 << do not use defines for the SPI pins SCK, MISO, MOSI - they are addressed by the SPI library>>
byte test;

void setup()
{
  SPI.setBitOrder(MSBFIRST);//Most Significant Bit First << default setting do not need >>
  SPI.setDataMode(SPI_MODE0);// Mode 0 Rising edge of data, keep clock low << default setting, do not need >>
  SPI.setClockDivider(SPI_CLOCK_DIV2);//Run the data in at 16MHz/2 - 8MHz <<  this  needs to go after SPI.begin(); >>
  
  //finally set up the Outputs
  pinMode(latch_pin, OUTPUT);//Latch
  pinMode(data_pin, OUTPUT);//MOSI DATA << do not need, addressed by SPI library >>
  pinMode(clock_pin, OUTPUT);//SPI Clock  << do not need, addressed by SPI library >>
  pinMode(blank_pin, OUTPUT);//Output Enable  important to do this last, so LEDs do not flash on boot up
  
  digitalWrite(blank_pin, HIGH);//shut down the led

  test = B11111111;

<< where is SPI.begin(); ?? >>
}

void loop()
{
  //disable pins
  PORTD |= 1<<blank_pin;
  //push the test byte
  SPI.transfer(test);
  
  // shift register to storage register
  PORTD |= 1<<latch_pin;//Latch pin HIGH
  PORTD &= ~(1<<latch_pin);//Latch pin LOW
  //enable pins
  PORTD &= ~(1<<blank_pin);//Blank pin LOW to turn on the LEDs with the new data
}

Thanks alot for the fast reply, The second lead of LEDs is connected i just stopped drawing since i guess it is not needed to understand what i am testing.

SRCLR is connected to +5V if its the (overlined MR PIN11 at IC)
OE Isnt connected to GND since i enable/disable the register myself. See the order of the code

  1. Disable outputs
  2. shift byte to register
  3. shift to storage (1 0 on the latch_pin)
  4. enable ouputs

I need this order to disable flickering lateron when its multiplexed. (Long to explain but in short ill call a method in 8kHz which will shift out bit to leds so it would flicker)

Do i need the 0.1uF from VCC (Register) to GN? Since i dont have any caps here.

Need the cap for sure.
Your loop doesn't leave OE/ on for very long, - also why you will not see more than a flicker as is. As a test add:
delay(2);
after this line:
//enable pins
PORTD &= ~(1<<blank_pin);//Blank pin LOW to turn on the LEDs with the new data

Thanks again,
I added a delay but it does not chance anything. I guess without the 0,1µF there is nothing happening(?!).
Where do i need to add it? Between GND and Vcc of the 74HC595? (e.g. RAD 0,1/100?)

Yes, 0.1uF or 100nF from '595's VCC to its Gnd.

Post your current code. What is the LED current resistor value?

Here's an example schematic with a couple of parts. Much easier to see than fritzing pictures, as the ICs are more than just a black box with no hint of the pin functions.

In the Fritzing one side of the LEDs is not connected to anything.

@groundfungus, Did you read Reply #2 before posting?

Sorry.

@CrossRoads i should have the commen Kathod LED Layout, just without a Cap. (need to buy some i guess) I got 120 Ohm resistors in front of some low cost test LEDs which need 1,7-2,7V. They are working just tested them without a register.

I got:

  1. MOSI(51 at board) at Pin14
  2. SCK (52 at board) at Pin11
  3. Storage register clock(49 at board) at Pin12 one high low switch to push register to storage ("latch_pin")
  4. Output enable at Pin 13 (48 at board) this should enable/disable the leds ("blank_pin")

Pin10 and Pin 16 of the IC is +5V as needed.

The current code:

#include <SPI.h>// SPI Library used to clock data out to the shift registers

// can use any pin you want to latch the shift registers
// push the to storage register, Pin 12 at IC
#define latch_pin 49
// to shut enable/disable the register. Low enables, Pin 13 at IC
#define blank_pin 48
// used by SPI, must be pin 51 at Mega 2560
#define data_pin 51
// used by SPI, must be 52 at mega 2560, Pin 11 at IC
#define clock_pin 52

byte test;

void setup()
{
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2);//Run the data in at 16MHz/2 - 8MHz
  
  //finally set up the Outputs
  pinMode(latch_pin, OUTPUT);//Latch
  pinMode(blank_pin, OUTPUT);//Output Enable  important to do this last, so LEDs do not flash on boot up
  
  digitalWrite(blank_pin, HIGH);//shut down the led
  test = B11111111;
}

void loop()
{
  //disable pins
  PORTD |= 1<<blank_pin;
  //push the test byte
  SPI.transfer(test);
  
  // shift register to storage register
  PORTD |= 1<<latch_pin;//Latch pin HIGH
  PORTD &= ~(1<<latch_pin);//Latch pin LOW
  //enable pins
  PORTD &= ~(1<<blank_pin);//Blank pin LOW to turn on the LEDs with the new data
  delay(2);
}

Edit:
Ordered some 100nF caps. (1-2Days)

Okay i added a 104 cap and noticed something which also caused that it didn't work. I did use the PORTD command and this does somehow not work. so i changed the commands where i disable or enable the pins to digitalWrite() and it works great. So here is what i got right now to test my setup and it works good:

#include <SPI.h>// SPI Library used to clock data out to the shift registers

// can use any pin you want to latch the shift registers
// push the to storage register, Pin 12 at IC
#define latch_pin 49
// to shut enable/disable the register. Low enables, Pin 13 at IC
#define blank_pin 48
// used by SPI, must be pin 51 at Mega 2560
#define data_pin 51
// used by SPI, must be 52 at mega 2560, Pin 11 at IC
#define clock_pin 52

byte test[8];

void setup()
{
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2);//Run the data in at 16MHz/2 - 8MHz
  
  //finally set up the Outputs
  pinMode(latch_pin, OUTPUT);//Latch
  pinMode(blank_pin, OUTPUT);//Output Enable  important to do this last, so LEDs do not flash on boot up
  
  digitalWrite(blank_pin, HIGH);//shut down the led
   digitalWrite(latch_pin, LOW);//shut down the led
  test[0] = B11111110;
  test[1] = B11111101;
  test[2] = B11111011;
  test[3] = B11110111;
  test[4] = B11101111;
  test[5] = B11101111;
  test[6] = B11011111;
  test[7] = B10111111;
}

int i = 0;
void loop()
{
  //disable pins
  
  //PORTD |= 1<<blank_pin;
  digitalWrite(blank_pin, HIGH);//shut down the led
  //push the test byte
  SPI.transfer(test[i]);
  i++;
  if(i >=8){
      i=0;
  }
  
  // shift register to storage register
  digitalWrite(latch_pin, HIGH);//shut down the led
  digitalWrite(latch_pin, LOW);//shut down the led
  //PORTD |= 1<<latch_pin;//Latch pin HIGH
  //PORTD &= ~(1<<latch_pin);//Latch pin LOW
  //enable pins
  digitalWrite(blank_pin, LOW);
  //PORTD &= ~(1<<blank_pin);//Blank pin LOW to turn on the LEDs with the new data
  delay(50);
}

can anyone explain why they dont work as i thought? i thought i can use it without a method to set the leds faster. (going to put the setting into a timer interupt in 8kHz cycles..)

Just to mention. It does even work without the 104 caps now. but guess its better to have them there. (Guess i already found it that portd just works with the first 8 digital pins?!)

Thanks for the help!
Regards
BennX