How can I find how to use C++ to communicate with my i2c DS1307 realtime clock ?

18 Nov 2011

Where can I find out how to do the bit level manipulation so I can read the data from my i2c device DS1307 real time clock. My programming experience is limited to VBA and the like. Attached is the DS1307 datasheet and I would like to know where to start with the mbed i2c library.Which reads and writes should I do and in what order ? /media/uploads/GregMartin/ds1307.pdf

#include "mbed.h"


I2C i2c(p9, p10);        // sda, scl
Serial pc(USBTX, USBRX); // tx, rx

const int addr = 0x68; // define the I2C Address

int main() {
  
    char cmd[10];
    
        cmd[0] = 0x0;            // pointer to command register
        cmd[1] = 0xd1;          //read address. I dont know if these is are correct addresses
        cmd[2]=0xd0 ;            //write address
        cmd[3]=0x03f;              //some address
        
        
                 
        i2c.write(addr, cmd, 2); // Send command string
        i2c.read(addr,cmd,3);
        pc.printf("cmd[2]= %x\n",cmd[2]);
        pc.printf("Mystring= %x\n",cmd[3]);
        
}
19 Jul 2014

change to

const int addr = 0xD0; // define the I2C Address [mbed]
const int addr = 0x68; // define the I2C Address [arduino]

I don't know which one is correct, since datasheet says 1101000

pak

21 Jul 2014

Gregory,

I use library http://mbed.org/users/leihen/code/RTC-DS1307/

Everything works well as far as the RTC functions go, though I am having a problem getting setSquareWaveOutput() to work

...kevin