Announcement

Collapse
No announcement yet.

I2C comunications with real time clock DS1307

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I2C comunications with real time clock DS1307

    Hi. ... I´m trying to connect with the real time clock DS1307.

    This is my code:

    I2C1_Open(I2C_SLOW, PA13, PA12 );
    I2C1_Idle();
    I2C1_Start();
    I2C1_Write(0xD0);
    I2C1_Write(0x00);

    I2C1_Stop();
    I2C1_Start();

    I2C1_Getn( buffer, 7 );

    I2C1_Stop();
    I2C1_Close();

    gfx_MoveTo(0, 30) ;
    for ( i := 0; i < 7; i++ )
    print( [HEX2]buffer[i],"\n" );
    next

    Doesn´t work.... Communication is established, but the answer is not correct.

    Fortunately I have an Arduino with a code that works fine. This is the I2C signals from Arduino:
    Click image for larger version

Name:	1.jpg
Views:	102
Size:	61.4 KB
ID:	39542

    This is my signal
    Click image for larger version

Name:	2.jpg
Views:	117
Size:	76.7 KB
ID:	39543

    The problem is in the answer of the clock. Arduino receives data from "D0" -> CORRECT, and the following data are correct too.
    My answer is from "FE" ????, and the data is corrupted.

    Why the blue line goes up at the end of the second packet in my signal ? ( Just before the Stop )

    Any suggestions ????
    Please ....

  • #2
    This code works !!!!

    This article was the key: http://dangerousprototypes.com/docs/...eal_time_clock

    I2C1_Open(I2C_SLOW, PA13, PA12 );
    I2C1_Idle();
    I2C1_Start();
    I2C1_Write(0xD0);
    I2C1_Write(0x00);

    I2C1_Start();
    I2C1_Write(0xD1);

    // Seconds, minutes, hours
    v := I2C1_Read();
    s := bcd2bin( v & 0x7F );
    I2C1_Ack();
    v := I2C1_Read();
    m := bcd2bin( v );
    I2C1_Ack();
    v := I2C1_Read();
    h := bcd2bin( v );
    I2C1_Ack();

    I2C1_Read();
    I2C1_Ack();

    // Day, month, year
    v := I2C1_Read();
    d := bcd2bin( v );
    I2C1_Ack();
    v := I2C1_Read();
    mm := bcd2bin( v );
    I2C1_Ack();
    v := I2C1_Read();
    y := bcd2bin( v ) + 2000;
    I2C1_Ack();

    I2C1_Stop();
    I2C1_Close();


    Thanks!

    Comment

    Working...
    X