newbee_2:
Through another arduino i am feeding 0x0F but in other arduino(receiver) i am reading all kind of junk values but not 0x0F what could be the mistake on my partif(val | 0x80) { // flag bit has reached the top of the byte so we've done 8 iterations
This doesn't do what you think it does, since the '|' operator is an OR, and the if statement will always be true. What you want is '&' which is an AND. I.e.:
if (val & 0x80) {
Now personally, I tend to prefer writing the above expression as:
if ((val & 0x80) != 0) {
You have mixed up the logic in that you should do the shift of value before doing the read and not after.
I would make 'val' a simple counter (and call it a more meaningful name). Something like:
void loop()
{
static byte num_bits = 0;
static byte value = 0;
clock = digitalRead(pin2);
if ((clock == HIGH) && (clock1 == LOW))
{
value = (value << 1) | digitalRead (pin4);
if (++num_bits >= 8) // have we done 8 iterations? If so print it out
{
Serial.print(value, HEX);
Serial.println();
num_bits = 0;
value = 0;
}
}
clock1= clock;
}