Go Down

Topic: How to read RTC from SD module using a MEGA (Read 329 times) previous topic - next topic

SuperCartman

Nov 30, 2015, 09:40 pm Last Edit: Nov 30, 2015, 10:38 pm by SuperCartman
Hello I am working on a data logger project that is writing Excel files and logging temperature. In each excel file I need a time_stamp at the date of creation.

I have this project fully functional on the Arduino UNO, but now that I need more memory I have upgraded to a MEGA. This issue here is that the logger is no longer working as it did on the UNO.

Writing and logging to the SD card is still working, my ISSUE is with the RTC!!! When I read from the clock I get a long line of gibberish instead of a date.


This is the sample of the code I am using:
Code: [Select]

   void readTime() {
   Wire.beginTransmission(DS1307);
   Wire.write(byte(0));
   Wire.endTransmission();
   Wire.requestFrom(DS1307, 7);
   second = bcdToDec(Wire.read());
   minute = bcdToDec(Wire.read());
   hour = bcdToDec(Wire.read());
   weekday = bcdToDec(Wire.read());
   monthday = bcdToDec(Wire.read());
   month = bcdToDec(Wire.read());
   year = bcdToDec(Wire.read());
 }

void printTime() {
//   char buffer[3];
//   const char* AMPM = 0;
   readTime();
   Serial.print(days[weekday-1]);
   Serial.print(" ");
   Serial.print(months[month-1]);
   Serial.print(" ");
   Serial.print(monthday);
   Serial.print(", 20");
   Serial.print(year);
   Serial.print(" ");
   if (hour > 12) {
     hour -= 12;
     AMPM = " PM";
   }
   else AMPM = " AM";
   Serial.print(hour);
   Serial.print(":");
   sprintf(buffer, "%02d", minute);
   Serial.print(buffer);
   Serial.println(AMPM);
 }



I am assuming it has to do with the communication pins between the MEGA and the SD module, could there be something else I am missing.

I really appreciate the help! Thank you!

el_supremo

Have you wired the RTC to the correct TWI pins on the Mega? 20 (SDA) and 21 (SCL)
And have you got a 4.7k pullup resistor on each of those pins?

Pete
Don't send me technical questions via Private Message.

Go Up