Go Down

Topic: Arduino Due Wire / RTC problem (Read 321 times) previous topic - next topic

evve

Nov 05, 2017, 06:00 pm Last Edit: Nov 05, 2017, 09:10 pm by evve
Hello all,

When i run the code below my Arduino Due will not sync with the DS1307. However when i remove the address from Wire.begin(42) ( change it just to Wire.begin() ) there is no problem with syncing. I tested this sketch on a Mega without any issues.

I use this library: https://raw.githubusercontent.com/bluesign2k/Arduino/d8d6d62853a5308c21b95dad4bdd64e358e857cc/hardware/arduino/sam/libraries/Wire/Wire.cpp

The rtc module is connected to 5V. For the connection to the Due i use a level shifter.

I need some advice on this. Thank you. Ed.

Code: [Select]

#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

#define DS1307_ADDRESS 0x68 //address RTC
byte zero = 0x00; //workaround for issue #527 (RTC)

void setup()  {
  Serial.begin(9600);
  while (!Serial) ; // wait until Arduino Serial Monitor opens    
  Wire.begin(42); //standaard i2c poort
}

void loop()
{ setSyncProvider(RTC.get);
  if(timeStatus()!= timeSet)
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");
  if (timeStatus() == timeSet) {
    digitalClockDisplay();
    Serial.println();
  } else {
    Serial.println("The time has not been set.  Please run the Time");
    Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
    Serial.println();
    delay(4000);
  }
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}





pylon

Code: [Select]
  Wire.begin(42); //standaard i2c poort

This put the Wire library in slave mode. To activate master mode you have to call the constructor without any parameters.

On the Mega the hardware doesn't know an explicit slave mode, so an initialization into slave mode allows it to act as a master too. Although that works it isn't correct.

evve

Thank you Pylon for putting me on track again.

Go Up