I made a sample using two of them using Arduino UNO.
So I did that like this:
(There aren't any resistor on that image, but there are 220ohm resistor on every LEDs.)
And uploaded this code.
//1.6us+62.5ns
#include <SPI.h>
#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))
int latchPin = 12;
int clockPin = 13;
int dataPin = 11;
byte data[]={ 0b10101010,0b11001100 };
void _595_out() {
cbi(PORTB, 4);
SPI.transfer(data[0] );
SPI.transfer( data[1] );
sbi(PORTB, 4);
}
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.begin();
}
void loop() {
_595_out();
}
And this worked as I expected. But, when I changed sketch like this,
//1.6us+62.5ns
#include <SPI.h>
#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))
#define CHIPNO 2
int latchPin = 12;
int clockPin = 13;
int dataPin = 11;
byte data[]={ 0b10101010,0b11001100 };
void _595_out() {
cbi(PORTB, 4);
SPI.transfer(data[0]);
SPI.transfer(data[1]);
sbi(PORTB, 4);
}
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.begin();
Serial.begin(9600);
}
void loop() {
for(unsigned int z = 0; z < 65535; z++) {
data[0] = z & 255;
data[1] = (z & 65280) >> 8;
Serial.println("A");
Serial.print(data[0]);
Serial.print("/");
Serial.println(data[1]);
Serial.println("B");
_595_out();
Serial.println("C");
delay(500);
}
}
74HC595s aren't working. Any LEDs aren't on.
Printing Serial works well. Only 74HC595s aren't working.
And Removing all Serial-related thing doesn't solved this problem.
Where did I do wrong?
Serial.begin()
? Please post the entire sketch that doesn't work.Serial.begin(9600);
ath the end of the setup function. Everything except these is same as the first code, so that's why I didn't upload the entire sketch... And shiftOut using SPI is working when I use first code, but isn't working when I change the code as I said.