diff --git a/avr/Makefile b/avr/Makefile index 459e5fc..778861e 100644 --- a/avr/Makefile +++ b/avr/Makefile @@ -15,7 +15,7 @@ OBJCOPY = $(CROSS)objcopy OBJCOPY_FLAGS = -S AVRDUDE = avrdude -AVRDUDE_DEVICE = /dev/cu.usbmodem1421 +AVRDUDE_DEVICE = /dev/ttyACM0 AVRDUDE_FLAGS = -c arduino -p atmega328p -b 115200 -D -P $(AVRDUDE_DEVICE) HEADERS_LOCAL = diff --git a/avr/send.c b/avr/send.c index 0af97cf..ab1fbdb 100644 --- a/avr/send.c +++ b/avr/send.c @@ -43,7 +43,7 @@ static void spi_init() { /* * Set output pins clear by default */ - PORTB &= ~(1 << PORTB4); + PORTB &= ~((1 << PORTB5) | (1 << PORTB4)); } static uint8_t spi_send_byte(uint8_t value) { @@ -51,27 +51,27 @@ static uint8_t spi_send_byte(uint8_t value) { i = 0; for (i=0; i<8; i++) { + PORTB |= (1 << PORTB5); + if (value & 0x80) { PORTB |= (1 << PORTB4); } else { PORTB &= ~(1 << PORTB4); } - value <<= 1; - - PORTB |= (1 << PORTB5); - - _delay_us(60); + _delay_us(140); ret <<= 1; - PORTB &= ~(1 << PORTB5); - if (PINB & (1 << PINB3)) { ret |= 1; } - _delay_us(60); + PORTB &= ~(1 << PORTB5); + + _delay_us(140); + + value <<= 1; } return ret; @@ -91,7 +91,9 @@ static void spi_send_packet() { (void)spi_send_byte( sum & 0x00ff); (void)spi_send_byte((sum & 0xff00) >> 8); - status = spi_send_byte(0); + _delay_us(1200); + + device = spi_send_byte(0); status = spi_send_byte(0); }