Permalink
Browse files

Updated to work with Kenny's new ID-2 chip.

This chip has a slightly different protocol, and uses 9600 bits/s serial.
  • Loading branch information...
1 parent 1c2e114 commit 054a7a063b426b680cbc5540c04e3898369903c0 @knielsen knielsen committed Nov 24, 2011
Showing with 35 additions and 6 deletions.
  1. +33 −5 doorduino.c
  2. +2 −1 softserial.c
View
@@ -166,23 +166,48 @@ handle_serial_input(void)
}
}
+static uint8_t
+hex2int(char c)
+{
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ else if (c >= 'a' && c <= 'f')
+ return c - ('a' - 10);
+ else if (c >= 'A' && c <= 'F')
+ return c - ('A' - 10);
+ else
+ return 0xff;
+}
+
static void
handle_rfid_input(void)
{
- static char buf[10];
+ static char buf[14];
static uint8_t idx = 0;
int c;
+ uint8_t checksum;
uint8_t i;
+
for (;;) {
c = softserial_getchar();
switch (c) {
case SOFTSERIAL_EOF:
return;
- case 10:
+ case 2:
idx = 0;
break;
- case 13:
- if (idx == 10 && cnt == 0) {
+ case 3:
+ if (idx == 14 && cnt == 0) {
+ /* Check for correct checksum and CR / LF */
+ checksum = 0;
+ for (i = 0; i < 12; i += 2)
+ checksum ^= ((hex2int(buf[i]) << 4) |
+ hex2int(buf[i+1]));
+ if (checksum)
+ break;
+ if (buf[12] != 13 || buf[13] != 10)
+ break;
+
/*
We got an RFID tag.
Copy it into the card reader buffer to
@@ -198,8 +223,11 @@ handle_rfid_input(void)
}
}
default:
- if (idx < 10)
+ if (idx < 14)
+ {
buf[idx++] = c;
+ second = 0;
+ }
break;
}
}
View
@@ -76,6 +76,7 @@ pin_8to13_interrupt()
delta = current - softserial_startbit_time;
while (softserial_bit_count < 8)
{
+ // delta * 154 <= 154 * 16e6 Hz / 256 clocks/timertick / 9600 baud * (count+1.5)
if ((uint16_t)delta * 154 <= (uint16_t)softserial_bit_count*1000 + 1500)
break;
/*
@@ -118,7 +119,7 @@ softserial_init(void)
timer0_clock_off();
timer0_interrupt_a_disable();
timer0_mode_normal();
- timer0_clock_d1024(); /* 16MHz / 256 -> 16usec / tick. */
+ timer0_clock_d256(); /* 16MHz / 256 -> 16usec / tick. */
pin_mode_input(SOFTSERIAL_RX_PIN);
softserial_pin_oldstate = pin_is_high(SOFTSERIAL_RX_PIN);

0 comments on commit 054a7a0

Please sign in to comment.