Browse Source

search rom works, but not completely reliable yet

pull/5/head
Youen Toupin 10 years ago
parent
commit
6b4f76c5f4
  1. 31
      OneWireIO.ino

31
OneWireIO.ino

@ -61,6 +61,8 @@ byte receivingBitPos = 0;
void setup() void setup()
{ {
owROM[7] = crc8((char*)owROM, 7);
led.outputMode(); led.outputMode();
owPin.inputMode(); owPin.inputMode();
owOutTestPin.outputMode(); owOutTestPin.outputMode();
@ -183,11 +185,14 @@ void onewireInterruptImpl(void)
resetStart = now; resetStart = now;
// read bytes
switch (status) { switch (status) {
case OS_WaitCommand: case OS_WaitCommand:
{ {
bool bit = readBit(); bool bit = readBit();
/*if (bit)
debug.SC_APPEND_STR("received bit 1");
else
debug.SC_APPEND_STR("received bit 0");*/
receivingByte |= ((bit ? 1 : 0) << receivingBitPos); receivingByte |= ((bit ? 1 : 0) << receivingBitPos);
++receivingBitPos; ++receivingBitPos;
@ -211,21 +216,12 @@ void onewireInterruptImpl(void)
} }
} }
} break; } break;
case OS_SearchRom:
{
} break;
} }
} }
bool ignoreNextFallingEdge = false; bool ignoreNextFallingEdge = false;
void onewireInterruptSearchROM() void onewireInterruptSearchROM()
{ {
/*unsigned long now = micros();
if (now < lastInterrupt + 20)
return; // don't react to our own actions
lastInterrupt = now;*/
if (ignoreNextFallingEdge) if (ignoreNextFallingEdge)
{ {
ignoreNextFallingEdge = false; ignoreNextFallingEdge = false;
@ -340,3 +336,18 @@ ISR(TIMER1_COMPA_vect) // timer1 interrupt
if (event != 0) if (event != 0)
event(); event();
} }
uint8_t crc8(char addr[], uint8_t len) {
uint8_t crc = 0;
while (len--) {
uint8_t inbyte = *addr++;
for (uint8_t i = 8; i; i--) {
uint8_t mix = (crc ^ inbyte) & 0x01;
crc >>= 1;
if (mix) crc ^= 0x8C;
inbyte >>= 1;
}
}
return crc;
}

Loading…
Cancel
Save