--- a/blackbox/main.c Sat Dec 03 11:11:06 2011 +0100 +++ b/blackbox/main.c Sat Dec 03 11:55:01 2011 +0100 @@ -32,6 +32,7 @@ volatile uint8_t transmit_len_queue; volatile uint16_t response; +volatile uint8_t response_len; volatile uint8_t timer0_delay; @@ -195,6 +196,7 @@ TCNT0 = TIMER0_250US; timer0_delay = TIMER0_2300NS; response = 0; + response_len = 0; TIMSK |= _BV(TOIE0); } @@ -235,16 +237,21 @@ } else { // we received a bit (logic low) response = response << 1; + response_len++; } } else { // okay, we have logic high response = response << 1; response |= 1; - //debug: - RS232_puts("ANSWER RX\n"); + response_len++; } - _delay_us(20); // wait some cycles - RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power + if (response_len == 15) { // maximum response length reached + RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power + TIMSK &= ~_BV(TOIE0); + } else { + _delay_us(20); // wait some cycles + RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power + } } else timer0_delay--; // 2.3 ms delay not reached yet } @@ -285,6 +292,15 @@ // check for short circuit on the rails check_rails_shortcut(); + if (response_len > 0) { + itoa(response, s, 2); + response_len = 0; + RS232_puts("ANSWER RX: "); + RS232_puts(s); + RS232_putc('\n'); + } + + // read in button presses btn_start = (PIN(SW_START_PORT) & _BV(SW_START)); if (old_start != btn_start) {