EDIT 4/2/18: The Arduino tutorial schematics have been corrected! See https://github.com/arduino/Arduino/issues/6433 for that issue.
I have a project where I am trying to load a 16-bit number onto an EEPROM using an Arduino hooked up to two 74HC595 Shift registers.
I'm loosely following this Arduino tutorial: https://www.arduino.cc/en/Tutorial/ShiftOut, but I'm getting unexpected outputs depending on the number I try to load into the register. I've reduced everything to as simple a setup as I can, and have spent several hours trying to figure out what the heck is going wrong... obviously to no avail.
Here is the schematic - with the exception that I moved the capacitor off of ST_CP (why would they put that in the tutorial?) to between power and ground:
Here is my code:
#define SHIFT_DATA 2
#define SHIFT_CLK 3
#define SHIFT_LATCH 4
void setup() {
pinMode(SHIFT_DATA, OUTPUT);
pinMode(SHIFT_CLK, OUTPUT);
pinMode(SHIFT_LATCH, OUTPUT);
int address = 0b1111111111111111; // Case 1
//int address = 0b0000000000000000; // Case 2
//int address = 0b0101010101010101; // Case 3
//int address = 0b1010101010101010; // Case 4
//int address = 0b0101100110101110; // Case 5
shiftOut(SHIFT_DATA, SHIFT_CLK, MSBFIRST, (address >> 8)); // Load first 8 bits
shiftOut(SHIFT_DATA, SHIFT_CLK, MSBFIRST, address); // Load second 8 bits
digitalWrite(SHIFT_LATCH, LOW);
digitalWrite(SHIFT_LATCH, HIGH);
digitalWrite(SHIFT_LATCH, LOW);
}
void loop() {
// none
}
Here is a picture of my breadboard setup with Case 1 loaded:
And here follows my test cases.
- All 1's (1111111111111111). Looks good.
- All 0's (0000000000000000). Looks good.
- Repeated 01's (0101010101010101). Looks good.
- Repeated 10's (1010101010101010). Output: 1010101000000000. First 8 bits match, last 8 are zeros. Huh?
- Random sequence (0101100110101110). Output: all over the place. Initially the first 8 bits match as in Case 4, but on repeated resets of the Arduino the output changes, with some weird momentary flickering going on for some of the LEDs. If I press it enough times I can get it back to the initial output, but never what I expect. I am completely stumped. Here is an animated gif of this behavior running on the breadboard: http://i.imgur.com/KEwpSXe.gifv.
What could my problem be? I assume it's something very simple and I'm being an idiot.