Thanks Nick. I appreciate your point. I am posting the code with a very minimal SD card interaction. And just to confirm, when the program boots it confirms the presence of the card. Just to be sure that the if(ValidDIN == 'S') remains false, I also another Boolean which is set to False always. And yet when the code compiles and starts running, it keeps rebooting. ( Since I got a warning about the size of this posting exceeded 9000 words, I had to remove the variable declaration section, RTC functions and other SD card functions as they anyway are working normally )
And unless I get over this, the project cannot move forward. Sigh.
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//================= SETUP =========================
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
void setup()
{
// START SERIAL FOR DEBUGGING
Serial.begin(9600);
// Usage : Serial.println(variable);
// START THE I2C INTERFACE
#define DS3231_I2C_ADDRESS 0x68 // 0x68 is the RTC address
Wire.begin();
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0xE); // Address the Control Register
Wire.write(0x00); // Write 0x0 to control Register
Wire.endTransmission();
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0xF); // Address the Status register
Wire.write(0x00); // Write 0x0 to Status Register
Wire.endTransmission();
// SETUP THE OUTPUT PIN and SPI select pins
pinMode(BuzzerOut, OUTPUT);
pinMode(BTState, OUTPUT);
pinMode(FltLedOut, OUTPUT);
pinMode(chipSelect, OUTPUT);
pinMode(etherSelect, OUTPUT);
pinMode(rfidSelect, OUTPUT);
digitalWrite( etherSelect, HIGH); // Permanently disable EThernet interface
// START THE LCD INTERFACE
lcd.begin(20, 4);
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.clear();
lcd.print(F( "VAP LUBE MANAGEMENT."));
lcd.setCursor(0, 1);
lcd.print(F( " Version : 1.00 "));
lcd.setCursor(0, 2);
lcd.print(F( "Checking the SD card"));
lcd.setCursor(0, 3);
lcd.print(F( "Interface.. Wait...."));
delay (2000);
digitalWrite( rfidSelect, HIGH);
if (!SD.begin(chipSelect)) {
lcd.clear();
lcd.print(F( "SD Card fail. Check!"));
return; // No card .. just return..
}
lcd.clear();
lcd.print(F( "SD Card check pass!!"));
delay(1000);
// SETUP THE OUTPUT PIN and SPI select pins
pinMode(BuzzerOut, OUTPUT);
pinMode(BTState, OUTPUT);
pinMode(FltLedOut, OUTPUT);
Serial.println(freeMemory());
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//================ SCAN LOOP ======================
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
void loop()
{
// ENDLESS LOOP EXECUTION STARTS HERE:
// Read the Push buttons for every scan..
ValidDIN = MyDIN.getKey();
if (HomeDisp_Gate) displayHome(); //Upddate the Home Screen with date time once every second
// =======================================
// RTC CLOCK SETTING ROUTINE
if ( ValidDIN == 'I' && RTC_Latch ) {
RTC_Latch = 0;
RTC_Set_Gate = 1;
HomeDisp_Gate = 0;
HomeDisp_3L_Lock = 0;
Ser_Rd_Latch = 0;
ValidDIN = '0'; // Flush the ValidDIN variable...
}
if (RTC_Set_Gate) Set_TimeOfRTC3231();
// =======================================
// READ SERIAL DATA AND STORE TO SD CARD
if ( ValidDIN == 'F' && Ser_Rd_Latch ) {
Ser_Rd_Latch = 0;
Ser_Rd_Gate = 1;
HomeDisp_Gate = 0;
timeOut = 0;
lcd.clear();
// Code to generate new number for greaseplanxxx.csv file.
sdFileNo = EEPROM.read (eepAddress); // Get the current file number stored in EEPROM
tempSDFileNo = sdFileNo; // Save the current file no to restore if SD write Timesout
sdFileNo ++ ; // Increment it to generate the next number
if (sdFileNo > 125) sdFileNo = 1; // Reset if file number is more than 200
EEPROM.write (eepAddress, sdFileNo); // Write the generated number to EEPROM
sprintf(sdFileName, "GPlan%03d.csv", sdFileNo); // Generate the new File name to get XLS data...
lcd.setCursor(0, 0);
lcd.write(sdFileName);
lcd.setCursor(0, 3);
lcd.print(F( "Awaiting Data......."));
recordCount = 0; // Reset Record Count...
}
if ( Ser_Rd_Gate && timeOut > 10000 ) { // Serial data not received in 10 secs ... time out.
Ser_Rd_Latch = 1;
Ser_Rd_Gate = 0;
HomeDisp_Gate = 1;
HomeDisp_3L_Lock = 1;
timeOut = 0;
lcd.clear();
EEPROM.write (eepAddress, tempSDFileNo); // Reset the generated number to EEPROM
}
else {
if (Ser_Rd_Gate) ReadAndStoreToSD(); // Wait for serial data...
//timeOut += ScanMs; // Have bypassed this... may not be required
}
//======================================
// Program runs normally only if SD card segment below is commented out..
if ( ValidDIN == 'S' && validRecord_Gate ) { // User has pressed Start....
lcd.clear();
//sdFileNo = 120;
File dataFile = SD.open("GPlan120.csv");
if (dataFile) {
dataFile.close();
//sprintf( LCDmsg, "%s", RFID);
//lcd.print(LCDmsg);
validRecord_Gate = 0;
}
else {
lcd.clear();
sprintf(sdFileName, " GPlan%03d.csv ", sdFileNo); // Use the file name to generate an error report..
lcd.write(sdFileName);
lcd.setCursor(0, 1);
lcd.print(F(" SD File Error !! "));
lcd.setCursor(0, 2);
lcd.print(F(" Reset and Verify.."));
while (1); // Hold the message...and wait for reset.
}
}
delay (ScanMs);
}// End of main loop.
//================ SCAN LOOP END =================