Comparing Serial bits

Hi,

I have some parallel to serial shift registers (74HC165) that are daisy chained together. Their outputs are transmitted serially together to the serial monitor.

For now I am looking at 16 bits (to learn, then I will need 64 bits) that are displayed on the serial monitor perfectly using some example code (InfectedBytes | Arduino ShiftIn) below. I would like to compare each of the 16 bits that are being printed on the serial monitor with say 0b0000000000000001. I am using the serial monitor as a visual aid to help me only. The aim is to make a cable tester with the 74HC565 serial to parallel shift register to output 64 bits, then the 74HC165 to read the bits from the other side of the cable in theory! If there are no discrepancies, it will pass the test. Any help in learning how to do this would be most appreciated, thanks.

#include <ShiftIn.h>
// Init ShiftIn instance with one chip.
// The number in brackets defines the number of daisy-chained 74HC165 chips
// So if you are using two chips, you would write: ShiftIn<2> shift;
ShiftIn<2> shift;

void setup() {
  Serial.begin(9600);
  // declare pins: pLoadPin, clockEnablePin, dataPin, clockPin
  shift.begin(8, 9, 11, 12);
}

void displayValues() {
  for(int i = 0; i < shift.getDataWidth(); i++)
    Serial.print( shift.state(i) ); // get state of button i
  Serial.println();
  
}

void loop() {
  if(shift.update()) // read in all values. returns true if any button has changed
    displayValues();
  delay(1);

}

an unsigned long is 64 bits. if you have the output value in one long variable and an input variable with the bits shifted in you can simply compare the two variables.

if you want to know which bits are different, do an exclusive OR, "^". you'd then need to shift the result, counting shifts to know which bit positions are different

to display the value thru the serial monitor, you'd need to break the variable into 8 bit bytes for sending. (you could set a byte pointer to the variable location to make is convenient to locate each byte)

gcjr:
an unsigned long is 64 bits.

…on some platforms.
On an AVR, it is 32 bits.

64 bit would be “unsigned long long” or “uint64_t” on AVR

what about uint64_t?

From the code example, how would I extract all the bits (64 potentially) into a variable using the uint64_t? ?

Thanks in advance!

With shift and bitwise OR operations, paying particular attention to data types to the right of the assignment…

e.g. 1ULL << x

my opinion is that , no matter the way you imlement it, it wont work efficiently. Why is that :

  1. Suppose you "insert" to the cable a longlong 64bit. ok. what you get from the other end, is not the real level on the cable out but "what the hardware sees". That is, you cannot be sure on the quality of the wire, on the current each wire can carry, even some milliamps for TTL or microamps for CMOS can make differense.
  2. Suppose you insert a HIGH on cable x and a LOW on cable x+1 (adjajent cables), and there is a short between them. What will the hardware see? Both LOW? Both HIGH? One HIGH and one LOW? It is undefined.

The best approach I have seen is a series of LEDs , sinking the current the cable is designed for.
Is 64 a big number of leds? ok, use 32 and test 2 times

Anyway, GoodLuck
PS I aggree this is not a "programming answer"

I would recommend doing it in 8-bit chunks. That is how they are read in, why not take advantage of it?
You could put the 8 bytes into an array, then compare them to the 8 bytes you are expecting.

Say you had 8 open-drain shift registers (TPIC6C595), that you clocked data into, such that only one output was low.
On the receive side you have the 8 '165s with pullup resistors.
You send out 8 bytes:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 - results in one output going low.

On the inside, you receive 8 bytes:
0xff, 0fxx, 0xff, 0xff, 0xfe, 0xff, 0ff, 0xfe
Do some simple math to flip them over:
0xff - byte received = inverted data. 0xff - 0xff = 0x00, 0xff - 0xfe - 0x01.
So you have:
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01.

Then compare the input to the output
Any bytes not matching = shorted pins, incorrect pins, open pins.
So in my example, you see you have a problem, likely 2 wires shorted, as you only expected one 1 input.
Some code like this for the comparison.

for (x = 0; x < 8; x=x+1){
  if (outArray [x] == inArray [x]){
  Serial.print("good block ");
  Serial.println (x);
  }
  else {
  Serial.print ("bad block ");
  Serial.print (x);
  Serial.print (" , expected ");
  Serial.print (outArrray[x], BIN);
  Serial .print (" , received ");
  Serial.println (inArray[x], BIN);
  }
}

Seems like a valid programming question to me.

GRuser:
PS I aggree this is not a "programming answer"

I mean : M y a n s w e r is not in the programming field.