From b14d45e4843fb3f7fca3b5cb1de69a33ab2a2a6d Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Sat, 26 Nov 2016 20:14:37 +0100 Subject: [PATCH] Switched to UART2 as UART1 does not work on my board Tested sending and Timeouts, looks good so far --- software/Arduino/Makefile | 2 +- software/Arduino/ardusss7.cpp | 27 ++++++++++++++------------- software/Arduino/ardusss7.h | 2 +- software/Arduino/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/software/Arduino/Makefile b/software/Arduino/Makefile index 6d67175..bfd1165 100644 --- a/software/Arduino/Makefile +++ b/software/Arduino/Makefile @@ -108,4 +108,4 @@ flash : all -U flash:w:$(OBJDIR)/$(AVRMCU)/$(TARGET).hex test : flash - screen $(ISPPORT) 38400 + screen $(ISPPORT) 9600 diff --git a/software/Arduino/ardusss7.cpp b/software/Arduino/ardusss7.cpp index d40dbbd..a1967be 100644 --- a/software/Arduino/ardusss7.cpp +++ b/software/Arduino/ardusss7.cpp @@ -5,7 +5,7 @@ SSS7Wrapper SSS7; -SSS7Wrapper::SSS7Wrapper() { +void SSS7Wrapper::init() { sss7_init(); this->setupUart(); @@ -33,38 +33,39 @@ void SSS7Wrapper::getReceived(uint8_t msg[SSS7_PAYLOAD_SIZE]) { void SSS7Wrapper::setupUart() { - UBRR1H = UBRR_VAL >> 8; // Setting baudrate - UBRR1L = UBRR_VAL & 0xFF; + UBRR2H = UBRR_VAL >> 8; // Setting baudrate + UBRR2L = UBRR_VAL & 0xFF; - UCSR1B = (1 << TXEN1) | (1 << RXEN1); // Enable TX and RX - UCSR1C = (1 << UCSZ11) | (1 << UCSZ10); // Asynchronous 8N1 + UCSR2B = (1 << TXEN2) | (1 << RXEN2); // Enable TX and RX + UCSR2C = (1 << UCSZ21) | (1 << UCSZ20); // Asynchronous 8N1 // flush UDR do { - UDR1; + UDR2; } - while (UCSR1A & (1 << RXC1)); + while (UCSR2A & (1 << RXC2)); // reset tx and rx complete flags - UCSR1A = (1 << RXC1) | (1 << TXC1); + UCSR2A = (1 << RXC2) | (1 << TXC2); - UCSR1B |= (1 << TXCIE1) | (1 << RXCIE1); // enable tx and rx interrupts + UCSR2B |= (1 << TXCIE2) | (1 << RXCIE2); // enable tx and rx interrupts } void uart_put_byte(uint8_t byte) { - UDR1 = byte; + UDR2 = byte; } uint8_t uart_get_byte() { - return UDR1; + return UDR2; } -ISR(USART1_RX_vect) { +ISR(USART2_RX_vect) { + //PORTB ^= (1 << PB7); sss7_process_rx(); } -ISR(USART1_TX_vect) { +ISR(USART2_TX_vect) { sss7_process_tx(); } diff --git a/software/Arduino/ardusss7.h b/software/Arduino/ardusss7.h index 56f6fd4..98007fc 100644 --- a/software/Arduino/ardusss7.h +++ b/software/Arduino/ardusss7.h @@ -5,7 +5,7 @@ class SSS7Wrapper { public: - SSS7Wrapper(); + void init(); uint8_t canSend(); void send(uint8_t msg[SSS7_PAYLOAD_SIZE]); uint8_t sendFailed(); diff --git a/software/Arduino/main.cpp b/software/Arduino/main.cpp index a93bd52..29b636a 100644 --- a/software/Arduino/main.cpp +++ b/software/Arduino/main.cpp @@ -1,10 +1,45 @@ #include +#include "ardusss7.h" void setup() { + Serial.begin(9600); + + Serial.print("Initializing SSS7..."); + SSS7.init(); + Serial.println("Done !"); }; void loop() { + uint8_t msg[SSS7_PAYLOAD_SIZE]; + memset(msg, 0, SSS7_PAYLOAD_SIZE); + msg[0] = 'H'; + msg[1] = 'e'; + msg[2] = 'l'; + msg[3] = 'l'; + msg[4] = 'o'; + msg[5] = ' '; + msg[6] = 'W'; + msg[7] = 'o'; + msg[8] = 'r'; + msg[9] = 'l'; + msg[10] = 'd'; + + + while(1) { + + Serial.println("Waiting to send"); + while(!SSS7.canSend()); + Serial.println("Sending ..."); + SSS7.send(msg); + while(!SSS7.canSend()); + //Serial.println("Finished Sending"); + if(SSS7.sendFailed()) { + Serial.println("Send failed"); + } + + _delay_ms(1000); + } };