Skip to content

Commit

Permalink
Revert "Revert "Improve debug environment (#130)" (#149)" (#152)
Browse files Browse the repository at this point in the history
This reverts commit 5d4ed2b.
  • Loading branch information
dmohns authored Dec 20, 2023
1 parent 51bbaff commit 67984bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
16 changes: 8 additions & 8 deletions firmware/src/SAM_UART.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand All @@ -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!!");
}
}
48 changes: 31 additions & 17 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -178,6 +190,8 @@ void setup() {
LoadActivationVariables(); // We load the activation variableS
break;
}

Serial2.println("Setup Complete! \n");
}

void loop() {
Expand Down

0 comments on commit 67984bb

Please sign in to comment.