Hello,
Please forgive my ignorance - I'm far more used to working with higher level languages, so getting down to the nitty gritty isn't something I'm particularly experienced with.
I'm reading data from a Weigand device, 34 bits in all, using interrupts with the following two functions from some example code;
void reader1One(void) {
reader1Count++;
reader1 = reader1 << 1;
reader1 |= 1;
}
void reader1Zero(void) {
reader1Count++;
reader1 = reader1 << 1;
}
for those that aren't familiar with weigand, it consists of two data lines, one pulling low is a zero, the other pulling low is a one. Simples.
Now, my issue comes when I have the data, I need to pull the following two segments of binary to get the information I want;
Top line: first piece of data required
Middle line: full data received on each card swipe (as read from the same code, printing a bit at a time to the serial console)
Last line: second piece of data required
110111110
0000110111110100110111110010110111
10011011111001
So I need 9 bits from the 5th bit, and then 14 bits from the 14th bit. Once I have 34 bits, I attempt the following.
int serialNumber=(reader1 >> 14) & 0x3fff;
int siteCode= (reader1 >> 5) & 0x1ff;
The first piece of data (110111110) should be (int)446. The second (10011011111001) should be 9977.
These are not the results I see from my code when doing Serial.Print() on each of the above variables.
Can anyone see where I've gone wrong?
Thanks in advance,
Mike.
FWIW, if the above isn't making sense, the full (hacked up) code can be found here:
http://pastebin.com/43iQ4Fud