diff --git a/firmware/src/SAM_UART.cpp b/firmware/src/SAM_UART.cpp index dcbf6e4f..790648ee 100644 --- a/firmware/src/SAM_UART.cpp +++ b/firmware/src/SAM_UART.cpp @@ -36,7 +36,7 @@ unsigned short ATM90E26_UART::AFECHIP(unsigned char RW, unsigned char address, output = (MSByte << 8) | LSByte; // join MSB and LSB; return output; } - Serial.println("Read failed"); + Serial2.println("Read failed"); delay(20); // Delay from failed transaction return 0xFFFF; } @@ -45,7 +45,7 @@ unsigned short ATM90E26_UART::AFECHIP(unsigned char RW, unsigned char address, else { byte atm90_chksum = ATM_UART->read(); if (atm90_chksum != host_chksum) { - Serial.println("Write failed"); + Serial2.println("Write failed"); delay(20); // Delay from failed transaction } } @@ -148,8 +148,8 @@ void ATM90E26_UART::SET_register_values() { // See pg 31 of datasheet. AFECHIP(0, CSOne, 0x327C); // Write CSOne, as self calculated - Serial.print("Checksum 1:"); - Serial.println( + Serial2.print("Checksum 1:"); + Serial2.println( AFECHIP(1, CSOne, 0x0000), HEX); // Checksum 1. Needs to be calculated based off the above values. @@ -178,8 +178,8 @@ void ATM90E26_UART::SET_register_values() { 0, CSTwo, 0x993B); // mt50, 0x13B5 Write CSTwo 0x6BB9, as self calculated 0x7F75 - Serial.print("Checksum 2:"); - Serial.println( + Serial2.print("Checksum 2:"); + Serial2.println( AFECHIP(1, CSTwo, 0x0000), HEX); // Checksum 2. Needs to be calculated based off the above values. @@ -190,10 +190,10 @@ void ATM90E26_UART::SET_register_values() { systemstatus = FETCH_SysStatus(); if (systemstatus & 0xC000) { // checksum 1 error - Serial.println("Checksum 1 Error!!"); + Serial2.println("Checksum 1 Error!!"); } if (systemstatus & 0x3000) { // checksum 2 error - Serial.println("Checksum 2 Error!!"); + Serial2.println("Checksum 2 Error!!"); } } diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index a037266f..b1a07939 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -54,8 +54,12 @@ void setup() { pinMode(red_led, OUTPUT); pinMode(green_led, OUTPUT); + Serial2.begin(115200); + Serial2.print("Device Powered! \n"); digitalWrite(buzzer, HIGH); + // Display Intro Screen. + Serial2.print("Setting up LCD... \n"); lcd.createChar(0, fe1); lcd.createChar(1, fe2); lcd.createChar(2, fe3); @@ -65,6 +69,8 @@ void setup() { lcd.setCursor(0, 1); lcd.print(" FIRST ELECTRIC "); + delay(2000); + lcd.clear(); lcd.setCursor(7, 0); lcd.write(byte(0)); @@ -75,25 +81,23 @@ void setup() { lcd.setCursor(8, 1); lcd.write(byte(3)); - ATM90E26.begin(9600); - AFE_chip.SET_register_values(); - delay(1000); - digitalWrite(buzzer, LOW); + Serial2.print("LCD Setup complete! \n"); - Serial2.begin(115200); - Serial2.print("working"); - Serial1.begin(115200); - delay(3000); - Serial1.write("AT+IPR=9600\r\n"); - Serial1.end(); - Serial1.begin(9600); + digitalWrite(buzzer, LOW); + // Begin Device Initialization. lcd.setCursor(0, 0); lcd.print(" SYSTEM BOOTING "); lcd.setCursor(0, 1); - lcd.print(" ## "); + lcd.print(" #------------# "); + // Configure GSM modem. Serial2.println("Initializing modem..."); + Serial1.begin(115200); + delay(3000); + Serial1.write("AT+IPR=9600\r\n"); + Serial1.end(); + Serial1.begin(9600); modem.restart(); String modemInfo = modem.getModemInfo(); lcd.setCursor(0, 0); @@ -110,17 +114,25 @@ void setup() { delay(2000); lcd.clear(); - if (!rtc.begin()) { + // Configure RTC + while (rtc.begin() == false) { lcd.print("Couldn't find RTC"); delay(2000); - while (1) - ; } if (!rtc.isrunning()) { lcd.print("RTC is NOT running!"); delay(2000); } initializeTime(); + + // Configure AFE + Serial2.print("Setting up AFE... \n"); + ATM90E26.begin(9600); + AFE_chip.SET_register_values(); + delay(1000); + Serial2.print("AFE Setup Complete! \n"); + + // Get Meter AFE checksum lcd.setCursor(0, 0); lcd.print("CSOne : "); lcd.setCursor(8, 0); @@ -130,9 +142,9 @@ void setup() { lcd.print("CSTwo : "); lcd.setCursor(8, 1); lcd.print(AFE_chip.FETCH_MeterCSTwo()); - delay(1000); + delay(3000); - // rtc eeprom + // Configure EEPROM // mem.writeLong(credit_eeprom_location, 200); // mem.writeLong(eeprom_location_cnt, token_eeprom_location); // delay(20); @@ -178,6 +190,8 @@ void setup() { LoadActivationVariables(); // We load the activation variableS break; } + + Serial2.println("Setup Complete! \n"); } void loop() {