diff --git a/software/AVR8/Makefile b/software/AVR8/Makefile index 405ebcf..6e8afdf 100644 --- a/software/AVR8/Makefile +++ b/software/AVR8/Makefile @@ -4,7 +4,7 @@ ISPPORT ?= /dev/ttyUSB0 VERSION = 0.1 -HEADERS = +HEADERS = sss7.h uart.h SRC = main.c sss7.c uart.c TARGET = sss7 OBJDIR = bin @@ -32,7 +32,7 @@ start: @echo ":: Building for $(AVRMCU)" @echo ":: MCU operating frequency is $(F_CPU)Hz" -$(OBJDIR)/$(AVRMCU)/%.o : %.c $(HEADERS) +$(OBJDIR)/$(AVRMCU)/%.o : %.c $(HEADERS) Makefile @mkdir -p $$(dirname $@) $(CC) $(CFLAGS) -c $< -o $@ diff --git a/software/AVR8/main.c b/software/AVR8/main.c index 18fb381..df74832 100644 --- a/software/AVR8/main.c +++ b/software/AVR8/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "uart.h" #include "sss7.h" @@ -11,6 +12,7 @@ int main(void) { uint8_t msg[SSS7_PAYLOAD_SIZE]; +memset(msg, 0, SSS7_PAYLOAD_SIZE); msg[0] = 'H'; msg[1] = 'e'; msg[2] = 'l'; @@ -23,6 +25,8 @@ msg[8] = 'r'; msg[9] = 'l'; msg[10] = 'd'; + + uart_init(); sss7_init(); sei(); @@ -32,6 +36,10 @@ while(1) { if(sss7_can_send()) { sss7_send(msg); } + while(!sss7_can_send()); + if(sss7_send_failed()) { + PORTB ^= (1 << PB2); + } _delay_ms(250); } diff --git a/software/AVR8/sss7.c b/software/AVR8/sss7.c index e309b05..9aaf671 100644 --- a/software/AVR8/sss7.c +++ b/software/AVR8/sss7.c @@ -61,12 +61,12 @@ void sss7_send(uint8_t msg[SSS7_PAYLOAD_SIZE]) { // Commit to send state sss7_state = SSS7_TX_HEADER; + sss7_tx_failed = 0; sss7_send_byte(SSS7_HEADER[0]); } ISR(USART_RXC_vect) { - PORTB ^= (1 << PB3); uint8_t byte = UDR; uint8_t crc = 0; @@ -120,7 +120,6 @@ ISR(USART_RXC_vect) { } ISR(USART_TXC_vect) { - PORTB ^= (1 << PB2); if(sss7_tx_last_ack) { uint8_t byte; diff --git a/software/AVR8/sss7.h b/software/AVR8/sss7.h index f4ab3db..3347100 100644 --- a/software/AVR8/sss7.h +++ b/software/AVR8/sss7.h @@ -33,7 +33,7 @@ static inline uint8_t sss7_can_send(void) { void sss7_send(uint8_t msg[SSS7_PAYLOAD_SIZE]); static inline uint8_t sss7_send_failed(void) { - return sss7_state != SSS7_IDLE && sss7_tx_failed; + return sss7_state == SSS7_IDLE && sss7_tx_failed; } static inline uint8_t sss7_has_received(void) {