diff --git a/firmware/src/SAM_UART.cpp b/firmware/src/SAM_UART.cpp index 790648ee..dcbf6e4f 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; } - Serial2.println("Read failed"); + Serial.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) { - Serial2.println("Write failed"); + Serial.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 - Serial2.print("Checksum 1:"); - Serial2.println( + Serial.print("Checksum 1:"); + Serial.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 - Serial2.print("Checksum 2:"); - Serial2.println( + Serial.print("Checksum 2:"); + Serial.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 - Serial2.println("Checksum 1 Error!!"); + Serial.println("Checksum 1 Error!!"); } if (systemstatus & 0x3000) { // checksum 2 error - Serial2.println("Checksum 2 Error!!"); + Serial.println("Checksum 2 Error!!"); } } diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index b1a07939..a037266f 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -54,12 +54,8 @@ 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); @@ -69,8 +65,6 @@ void setup() { lcd.setCursor(0, 1); lcd.print(" FIRST ELECTRIC "); - delay(2000); - lcd.clear(); lcd.setCursor(7, 0); lcd.write(byte(0)); @@ -81,23 +75,25 @@ void setup() { lcd.setCursor(8, 1); lcd.write(byte(3)); - Serial2.print("LCD Setup complete! \n"); - + ATM90E26.begin(9600); + AFE_chip.SET_register_values(); + delay(1000); digitalWrite(buzzer, LOW); - // Begin Device Initialization. - lcd.setCursor(0, 0); - lcd.print(" SYSTEM BOOTING "); - lcd.setCursor(0, 1); - lcd.print(" #------------# "); - - // Configure GSM modem. - Serial2.println("Initializing modem..."); + Serial2.begin(115200); + Serial2.print("working"); Serial1.begin(115200); delay(3000); Serial1.write("AT+IPR=9600\r\n"); Serial1.end(); Serial1.begin(9600); + + lcd.setCursor(0, 0); + lcd.print(" SYSTEM BOOTING "); + lcd.setCursor(0, 1); + lcd.print(" ## "); + + Serial2.println("Initializing modem..."); modem.restart(); String modemInfo = modem.getModemInfo(); lcd.setCursor(0, 0); @@ -114,25 +110,17 @@ void setup() { delay(2000); lcd.clear(); - // Configure RTC - while (rtc.begin() == false) { + if (!rtc.begin()) { 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); @@ -142,9 +130,9 @@ void setup() { lcd.print("CSTwo : "); lcd.setCursor(8, 1); lcd.print(AFE_chip.FETCH_MeterCSTwo()); - delay(3000); + delay(1000); - // Configure EEPROM + // rtc eeprom // mem.writeLong(credit_eeprom_location, 200); // mem.writeLong(eeprom_location_cnt, token_eeprom_location); // delay(20); @@ -190,8 +178,6 @@ void setup() { LoadActivationVariables(); // We load the activation variableS break; } - - Serial2.println("Setup Complete! \n"); } void loop() {