DS1307 SPI incorrect values

Hi, i can't find solution at my problem,

maybe someone coud help me !

I'm running with an arudino MEGA2560, DS1307 is connected via I2C, SD Card is connected to SPI.

On the first code, it is a function to acquire date on RTC DS1307 (date and time variables are declared as byte)

On the second part of code, it a a string arrangement to send values to SD CARD file. For date and time values, the data sent to the file are always "10", i can't have the real date and time values, i'm sure that the DS1307 is giving good informations (it's working with demo program)

I feel that the problem is in string arrangement with date/time variable format.

Please can you help me ?


void getDateDs1307()
  // Reset the register pointer
  Wire.requestFrom(0x68, 7);

  second     = bcdToDec(Wire.receive() & 0x7F);
  minute     = bcdToDec(Wire.receive());
  hour       = bcdToDec(Wire.receive() & 0x3F);  // Need to change this if 12 hour am/pm
  dayOfWeek  = bcdToDec(Wire.receive());
  dayOfMonth = bcdToDec(Wire.receive());
  month      = bcdToDec(Wire.receive());
  year       = bcdToDec(Wire.receive());
  Serial.print(" ");
  Serial.print(year, DEC);

dataString = "*** ";                      // *** sur la chaine de caractères
        dataString += commentaire;                // Ajout de la chaine commentaire dans la chaine de caractères
        dataString += "***";                      // *** sur la chaine de caracteres
        dataString += ";";
        dataString += hour;
        dataString += ":";
        dataString += minute;
        dataString += ":";
        dataString += (second,DEC);
        dataString += ";";
        dataString += (dayOfMonth,DEC);
        dataString += "/";
        dataString += (month,DEC);
        dataString += "/20";
        dataString += (year,DEC);
        dataString += (second,DEC);

The String class is doing exactly what you tell it here. You have supplied the String += operator function with garbage, so it tacks garbage onto your string. No surprise there.

The (variable, type) arguments to the Serial.print() method are not meaningful everywhere. Just because Serial.print() correctly interprets a pair of arguments does not mean that every function ever developed will interpret the same values the same way.

Ok PaulS, but how do you explain that there is value "10" for all Date/time values ?

I fell that my values are not formatted correctly, but how do you do it ?

Please let me know,


Thank you Paul for your informations !

I found my mistake,
i changed the Date/Time values type to INT, removed ,DEC at the end of each string addition, everything is running bright !

Many thanks for your help