Hey guys,
I'm trying to figure out how to read back the data shifted to four 74HC595 for comparision to check if there was an error during transmission.
Here is the code I use:
#define PIN_SHIFT 8 // connected to SHCP
#define PIN_STORE 9 // connected to STCP
#define PIN_DATA 10 // connected to DS
#define PIN_RETURN 11 // connected to Q7S of last 74HC595
uint32_t count = 0;
uint32_t rcount = 0;
byte data1 = 0;
byte data2 = 0;
byte data3 = 0;
byte data4 = 0;
void setup()
{
pinMode(PIN_STORE, OUTPUT);
pinMode(PIN_SHIFT, OUTPUT);
pinMode(PIN_DATA, OUTPUT);
pinMode(PIN_RETURN, INPUT);
digitalWrite(PIN_STORE, HIGH);
delay (5000);
}
void loop ()
{
digitalWrite(PIN_STORE, LOW);
shiftOut(PIN_DATA, PIN_SHIFT, MSBFIRST, count >> 24);
shiftOut(PIN_DATA, PIN_SHIFT, MSBFIRST, count >> 16);
shiftOut(PIN_DATA, PIN_SHIFT, MSBFIRST, count >> 8);
shiftOut(PIN_DATA, PIN_SHIFT, MSBFIRST, count);
digitalWrite(PIN_STORE, HIGH);
digitalWrite(PIN_STORE, LOW);
Serial.print(count, BIN);
Serial.println();
data1 = shiftIn(PIN_RETURN, PIN_SHIFT, MSBFIRST);
data2 = shiftIn(PIN_RETURN, PIN_SHIFT, MSBFIRST);
data3 = shiftIn(PIN_RETURN, PIN_SHIFT, MSBFIRST);
data4 = shiftIn(PIN_RETURN, PIN_SHIFT, MSBFIRST);
Serial.print(data1, BIN);
Serial.println();
Serial.print(data2, BIN);
Serial.println();
Serial.print(data3, BIN);
Serial.println();
Serial.print(data4, BIN);
Serial.println();
rcount == 0;
rcount += (uint32_t)data1 << 24;
rcount += (uint32_t)data2 << 16;
rcount += (uint32_t)data3 << 8;
rcount += (uint32_t)data4;
Serial.print(rcount, BIN);
Serial.println();
Serial.println();
count ++;
delay (50);
}
And here are some results from the serial monitor:
1001101110000
0
0
100110
11100000
1011110011110111000101000
1001101110001
0
0
100110
11100011
1011110100001010100001011
1001101110010
0
0
100110
11100100
1011110100011101111101111
1001101110011
0
0
100110
11100111
1011110100110001011010110
1001101110100
0
0
100110
11101000
1011110101000100110111110
It looks like there is one additional digit at the end of data4. How can I get rid of that?
Combining the bytes data1 - data4 into one uint32_t doesn't work at all. What am I dooing wrong there? Can I also compare count and rcount bytewise?
Thank you in advance and best regards!
Dominic