DS1307 can not read and write time in arduino.

Thread Starter

dreamtale

Joined Oct 30, 2014
24
hello everyone
In mid-November, I have designed a shield based on arduino.I have wrote two posts.http://forum.allaboutcircuits.com/t...-back-integrates-a-variety-of-sensors.103659/ and http://forum.allaboutcircuits.com/threads/arduino-shield-with-magnetometer-clock-and-oled.103193/ I have to debug a week.However, it does not work.The OLED display and bluetooth is ok.
Here is my sch,
20141202175414.jpg
Here is my pcb
IMG_0492.JPG
Code:
void setup() {
  Wire.begin();
  Serial.begin(57600);
}

void loop() {
  if (Serial.available()) {  // Look for char in serial que and process if found
    command = Serial.read();
    if (command == 84) {      //If command = "T" Set Date
      setDateDs1307();
      getDateDs1307();
      Serial.println(" ");
    }
    else if (command == 81) {  //If command = "Q" RTC1307 Memory Functions
      delay(100);   
      if (Serial.available()) {
        command = Serial.read();
      
        // If command = "1" RTC1307 Initialize Memory - All Data will be set to 255 (0xff).
        // Therefore 255 or 0 will be an invalid value.
        if (command == 49) {
        
          // 255 will be the init value and 0 will be cosidered an error that
          // occurs when the RTC is in Battery mode.
          Wire.beginTransmission(clockAddress);
        
          // Set the register pointer to be just past the date/time registers.
          Wire.write(byte(0x08));
          for (int i = 1; i <= 27; i++) {
            Wire.write(byte(0xff));
            delay(100);
          } 
          Wire.endTransmission();
          getDateDs1307();
          Serial.println(": RTC1307 Initialized Memory");
        }
        else if (command == 50) {      //If command = "2" RTC1307 Memory Dump
          getDateDs1307();
          Serial.println(": RTC 1307 Dump Begin");
          Wire.beginTransmission(clockAddress);
          Wire.write(byte(0x00));
          Wire.endTransmission();
          Wire.requestFrom(clockAddress, 64);
          for (int i = 1; i <= 64; i++) {
            test = Wire.read();
            Serial.print(i);
            Serial.print(":");
            Serial.println(test, DEC);
          }
          Serial.println(" RTC1307 Dump end");
        }
      }
    }
    Serial.print("Command: ");
    Serial.println(command);  // Echo command CHAR in ascii that was sent
  }

  command = 0;  // reset command                
  delay(100);
}
Time is always parked in the 45:85:85,I know this is the wrong data.I use two leonardo to test.Unfortunately, I still did not get the correct data.Then,I suspect that the IIC on my leonardo is broken.
I've used other IIC devices, I put GY-30 connected to leonardo, and the code I‘ve been used,it can't work.I borrowed a Duemilanove from others.The GY-30 can work,and the DS1307 in my shield doesn't work.Now I have no idea.anyone can help me,and anyone can upload code about DS1307 base on arduino,In order to confirm the problem in my code or on my PCB.
Thanks
dreamtale
 

Papabravo

Joined Feb 24, 2006
21,226
The problem is obvious to even a casual observer. SDA must be bi-directional on a bit by bit basis so that the ACK pulse from the device can get back to the master. Your use of a FET as a level translator has borked the protocol.
 

Thread Starter

dreamtale

Joined Oct 30, 2014
24
Thanks,I don't think so,I do not konw why you said that FET as a level translator borked the protocol.but the FET also use in bluttooth,The bluetooth is OK.Can you tell me clear?
 

Papabravo

Joined Feb 24, 2006
21,226
What makes you think I2C and Bluetooth are related? Do you understand that the SDA line (Net A4) needs to pass signals in both directions during a transfer so that the slave device can ACK (acknowledge) the transmisstions of the master. Any circuit element like a FET or an FPGA that does not allow signals to propagete in both directions will bork the I2C protocol. But hey if you're so smart why are you asking me?
 

ErnieM

Joined Apr 24, 2011
8,377
Now gentlemen, let's, play nice. :p

The level translators look similar to a Sparkfun design listed as "bi directional." I believe there exists a Phillips app note describing similar circuits. They do require very low threshold devices, so careful if you substuited for that Ap2306

I say "similar" as Sparkfun's schematic has no series resistor in the gate. Beyond slowing things down I don't see the need for that part.

dreamtale: I2C has no minimum speed. That means you do not need anything beyond a voltmeter (or a pair of LEDs) to debug the interface. So write some simple I2C code where you can watch the transactions bit by bit to see what is going back and fourth.

The first critical bit of information is the ACK bit from slave to master after the first byte containing the slave address. If that is not there, nothing else following will work.
 

Thread Starter

dreamtale

Joined Oct 30, 2014
24
What makes you think I2C and Bluetooth are related? Do you understand that the SDA line (Net A4) needs to pass signals in both directions during a transfer so that the slave device can ACK (acknowledge) the transmisstions of the master. Any circuit element like a FET or an FPGA that does not allow signals to propagete in both directions will bork the I2C protocol. But hey if you're so smart why are you asking me?
well,About some of the features mos tube, I did not fully understand. Ignore other reasons, the level is between RTC and arduino compatible. I will tear down AP2306, and the pull-up resistor change for 4.7K. I'll test it as soon as possible.however,Thanks.
 

Thread Starter

dreamtale

Joined Oct 30, 2014
24
What makes you think I2C and Bluetooth are related? Do you understand that the SDA line (Net A4) needs to pass signals in both directions during a transfer so that the slave device can ACK (acknowledge) the transmisstions of the master. Any circuit element like a FET or an FPGA that does not allow signals to propagete in both directions will bork the I2C protocol. But hey if you're so smart why are you asking me?
Yeah,Thanks,If there are no FET, DS1307 to work properly.
 

Thread Starter

dreamtale

Joined Oct 30, 2014
24
Now gentlemen, let's, play nice. :p

The level translators look similar to a Sparkfun design listed as "bi directional." I believe there exists a Phillips app note describing similar circuits. They do require very low threshold devices, so careful if you substuited for that Ap2306

I say "similar" as Sparkfun's schematic has no series resistor in the gate. Beyond slowing things down I don't see the need for that part.

dreamtale: I2C has no minimum speed. That means you do not need anything beyond a voltmeter (or a pair of LEDs) to debug the interface. So write some simple I2C code where you can watch the transactions bit by bit to see what is going back and fourth.

The first critical bit of information is the ACK bit from slave to master after the first byte containing the slave address. If that is not there, nothing else following will work.
Well,If there are no FET, DS1307 can work properly.I'm sure I made a mistake should not be
 
Top