I´m having trouble with Arduino Uno and a 16-bit shift register made out of two CD4094´s.
The program appears to be working, but the leds connected on the outputs of the shift registers do nothing. What am I doing wrong ?
#include <avr/pgmspace.h>
#include <SPI.h>
const int latchPin = 10; //Pin connected to STR(pin 1) of HEF4094
//clock = 13, mosi = 11
const int eprom[12] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800};
int address = 0;
byte i = 0;
void setup() {
// put your setup code here, to run once:
pinMode(latchPin, OUTPUT);
digitalWrite(latchPin, LOW);
SPI.beginTransaction(SPISettings(500000, LSBFIRST, SPI_MODE0)); // initialize SPI
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
address = eprom[i];
Serial.print(i);
Serial.print(" ");
Serial.println(address, HEX);
Serial.println(" ");
addressOut(address % 256, address / 256);
delay(1000);
i++;
if(i > 11) i = 0;
}
void addressOut(byte addressLow, byte addressHigh)
{
digitalWrite(latchPin, HIGH);
SPI.transfer(addressLow);
SPI.transfer(addressHigh);
//delay(1);
digitalWrite(latchPin, LOW);
}
And apparently Arduino needs to be connected to USB for the program to work at all (?)
(It would be interesting to know tough why the version above didn´t work.)
Just found and solved a problem using daisy chained 4094 shift registers with Arduino SPI_MODE0 that I will add here for future reference.
Use the Q'S output (pin 10), not QS (pin 9)!
Data is shifted out of QS on the rising clock edge, just before it is clocked into the next device. It works sometimes but as the number of devices on the daisy chain increases so does the chance of errors.
The output on Q'S changes on the falling clock edge, so it's always ready to be clocked in on the next rising edge.