# HG changeset patch # User Malte Bayer # Date 1322909701 -3600 # Node ID c261350bb39431320d9a57b283cf08b1d5c3b53a # Parent b83d239fe71948480c4305d0353ac791405afbe7 fixed shortcut detection diff -r b83d239fe719 -r c261350bb394 blackbox/Makefile --- a/blackbox/Makefile Sat Dec 03 11:11:06 2011 +0100 +++ b/blackbox/Makefile Sat Dec 03 11:55:01 2011 +0100 @@ -1,6 +1,7 @@ PRG=main MCU=atmega16 +#FUSES=-U lfuse:w:0x3f:m -U hfuse:w:0xd8:m FUSES=-U lfuse:w:0x2f:m -U hfuse:w:0xc8:m BOOTFUSES=-U lfuse:w:0xff:m -U hfuse:w:0xce:m @@ -9,7 +10,7 @@ F_CPU = 8000000 -BAUD=38400 +BAUD=57600 ISP_BAUD = 115200 #SRC = main.c seriald.c driver/ADC.c driver/clock.c driver/timer.c diff -r b83d239fe719 -r c261350bb394 blackbox/lowlevel.c --- a/blackbox/lowlevel.c Sat Dec 03 11:11:06 2011 +0100 +++ b/blackbox/lowlevel.c Sat Dec 03 11:55:01 2011 +0100 @@ -50,8 +50,6 @@ RS232_init(); // initialize RS485 interface - RS232_puts_p(PSTR("CARRERA beta loading\n")); - initADC(); SFIOR = 0; @@ -108,11 +106,14 @@ OCR1A = TIMER1_7500NS; TIMSK |= 1<0) { if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) != 0) return 0; _delay_us(20); + i--; } if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) { cli(); // disable ALL Interrupts @@ -136,13 +138,13 @@ LED(2, 2); LED(4, 2); LED(5, 2); - _delay_ms(100); + blinkdelay(); LED(3, 2); - _delay_ms(100); + blinkdelay(); LED(3, 2); - _delay_ms(100); + blinkdelay(); LED(3, 2); - _delay_ms(100); + blinkdelay(); LED(3, 2); } } diff -r b83d239fe719 -r c261350bb394 blackbox/main.c --- 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) {