CD74HC595 Binary Headache...

Hello, I have an issue with CD74HC595E IC that won’t produce the expected output, I think it is a logic issue but I cannot figure out the problem and the datasheet or application notes did not help. Below is the behavior I see followed by the code implementation.


Behavior

I have the following setup and I am using a simple led bar for the output

unsigned char Q_OFF = B00000000;
unsigned char QA = B00000001;
unsigned char QB = B00000010;
unsigned char QC = B00000100;
unsigned char QD = B00001000;
unsigned char QE = B00010000;
unsigned char QF = B00100000;
unsigned char QG = B01000000;
unsigned char QH = B10000000;

At first I thought maybe the datasheet did not match the IC.
It is a different issue though because when I mix the inputs I get weird results:

//INPUT → LEDS OUTPUT (1 = HIGH LED PIN)
Q_OFF = B00000000 → 00000010
QA = B00000001 → 00000100
QB = B00000010 → 00001000
QC = B00000100 → 00010000
QD = B00001000 → 00100000
QE = B00010000 → 01000000
QF = B00100000 → 10000000
QG = B01000000 → 00000000
QH = B10000000 → 00000001

QA | QB → 00000110 (I was expecting 00001100)
QA | QB | QC → 00001110 (I was expecting 00011100)
QA | QH → 00010001 (I was expecting 00000101)

That makes no sense to me and the datasheet does not mention anything about the binary organization of the serial input of that IC. The Application Notes from TI are completely useless with tones of irrelevant information and lacking implementation example it is so bad that I am starting to think that they purposely don’t want people to use their IC. How can a smaller company like Atmel be so Designer friendly and a big company like TI be so out of touch with the their potential customer base? I am now thinking of trashing that IC from my design and ordering an IC from a different vendor but still it is frustrating to not understand what is going wrong and to not have a descent usage explanation from the datasheet.


CODE

const int clockPin = 9; //RCLK,SRCLK
const int dataPin = 8; //SER
const int latchPin = 10; //OE active LOW

int Q_OFF = B00000000; // leds output → 00000010
int QA = B00000001; // leds output → 00000100
int QB = B00000010; // leds output → 00001000
int QC = B00000100; // leds output → 00010000
int QD = B00001000; // leds output → 00100000
int QE = B00010000; // leds output → 01000000
int QF = B00100000; // leds output → 10000000
int QG = B01000000; // leds output → 00000000
int QH = B10000000; // leds output → 00000001

int data;

int dispTime = 1000;

void setup() {
Serial.begin(9600);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, LOW);
digitalWrite(latchPin, HIGH); // latchPin is active LOW on that IC
}

void loop() {

for (int i=0; i<9; i++)
{

if (i==0) data = Q_OFF;
if (i==1) data = QA | QB; //QA
if (i==2) data = QA | QB | QC; //QB;
if (i==3) data = QA | QH; //QC;
if (i==4) data = QD;
if (i==5) data = QE;
if (i==6) data = QF;
if (i==7) data = QG;
if (i==8) data = QH;

//data = ~data;
//data++;
latchRegister(data);
Serial.println(i);
}
}

void latchRegister(byte data){
digitalWrite(clockPin, LOW); //MUST BE BROUGHT LOW BEFORE SHIFTOUT STARTS SINCE THE DEVICE USES RISING EDGE
shiftOut(dataPin, clockPin, LSBFIRST, data); //Sends the lower 8bits of the data int
digitalWrite(latchPin, LOW);
delay(dispTime);
digitalWrite(latchPin, HIGH);
}

Please use code tags, see the how to use this forum sticky.

TI data sheets are not designed for beginners, get a data sheet for the same IC from another manafacaturer they are all the same chip. It does give you the information you want you are just not seeing it. Once you have corrected that post we can try and unpick whip here you are going wrong. A schematic would be good as well.