Author Topic: [Solved]DS1307 communication I2c  (Read 2310 times)

0 Members and 1 Guest are viewing this topic.

Offline BlogRahulTopic starter

  • Regular Contributor
  • *
  • Posts: 75
  • Country: in
[Solved]DS1307 communication I2c
« on: December 15, 2021, 04:37:19 pm »

What would be the message length of the I2C bus?
  When 8-bit uC writing two register's of DS1307 [ Seconds Address (00h), Minutes address (01h)]


Bus length : start bit,  0xD0, 0x00, 0x11, stop bit;

I think the I2C bus sends a total of 26 bits and 29 clock pulses to write Seconds and Minutes registers

Does I2C send a total of 26 bits or 24 bits?
« Last Edit: December 17, 2021, 12:52:28 pm by BlogRahul »
 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 334
  • Country: gb
    • Woofys Place
Re: Message length when communicating with DS1307
« Reply #1 on: December 15, 2021, 05:26:48 pm »
Start and stop are not so much bits as sequences, there is no SCL clock. Its SDA going low/high while SCL is high. They take time though so count them as bits if you choose.
so 24 data bits
3 Ack bits
Plus start/stop if you want to count them.

[edit]
Just to be clear, your example writes 11 to the seconds register only, you're not writing anything to the minutes reg.
« Last Edit: December 15, 2021, 09:35:15 pm by woofy »
 

Offline BlogRahulTopic starter

  • Regular Contributor
  • *
  • Posts: 75
  • Country: in
Re: Message length when communicating with DS1307
« Reply #2 on: December 16, 2021, 11:25:46 am »
.
Just to be clear, your example writes 11 to the seconds register only, you're not writing anything to the minutes reg.
correct It should be anything like 0xD0, 0x00, 0x11 0x12

3 Ack bits

When the master writes to the slave,  Who generates ack/NAK signal master or slave?
 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 334
  • Country: gb
    • Woofys Place
Re: Message length when communicating with DS1307
« Reply #3 on: December 16, 2021, 01:46:18 pm »

When the master writes to the slave,  Who generates ack/NAK signal master or slave?

The slave.

When reading from the slave its the master that must provide the ack/nack, therefore the ack/nack is generated by whoever is receiving the data byte.
The SCL clock is always generated by the master.

Offline BlogRahulTopic starter

  • Regular Contributor
  • *
  • Posts: 75
  • Country: in
Re: Message length when communicating with DS1307
« Reply #4 on: December 17, 2021, 10:29:20 am »
What are the steps to read the sequence of bytes from the I2C device? like if I need to read two registers seconds and minutes What will happen?

Here is my understanding

    Master send repeat start on the I2C bus
    Master send slave address 0xD1 reading mode 
    Master generates ACK/NAK
    Master sends the address of seconds 0x00
    Master generates ACK
    Master sends the address of minutes 0x01
    Master generates NAK after the last byte




« Last Edit: December 17, 2021, 10:31:05 am by BlogRahul »
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2300
  • Country: gb
Re: Message length when communicating with DS1307
« Reply #5 on: December 17, 2021, 10:47:56 am »

(1) Download PulseView from here and install it

(2) Download example DS1307 data from here (the .sr files)

(3) Open a .sr file in PulseView to see a capture of I2C data. Then add the decoder for DS1307.

(4) Zoom and pan to view all the detail you want to see in DS1307 transactions. See example screenshot attached.
 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 334
  • Country: gb
    • Woofys Place
Re: Message length when communicating with DS1307
« Reply #6 on: December 17, 2021, 11:25:05 am »
What are the steps to read the sequence of bytes from the I2C device? like if I need to read two registers seconds and minutes What will happen?

Here is my understanding

    Master send repeat start on the I2C bus
    Master send slave address 0xD1 reading mode 
    Master generates ACK/NAK
    Master sends the address of seconds 0x00
    Master generates ACK
    Master sends the address of minutes 0x01
    Master generates NAK after the last byte


You need tell the DS1307 where you want to read from, also read again my post above on who generates the ack.

To read seconds and minutes:
1. Send a start sequence
2. Send 0xD0, slave generates ack. (Yes, its a write command!)
3. Send 0x00, the address of the seconds reg, slave generates ack.
4. Send start sequence again, (restart)
5. Send 0xD1, slave generates ack. (Now its a read command)
6. Read seconds reg, master generates ack.
7. Read minutes reg, master generates ack.
8. Send stop sequence.

Offline retiredfeline

  • Frequent Contributor
  • **
  • Posts: 539
  • Country: au
Re: Message length when communicating with DS1307
« Reply #7 on: December 17, 2021, 11:30:24 am »
Further to the previous answer figure 6 on page 13 of the Maxim datasheet shows the transaction.
 
The following users thanked this post: BlogRahul

Offline BlogRahulTopic starter

  • Regular Contributor
  • *
  • Posts: 75
  • Country: in
Re: Message length when communicating with DS1307
« Reply #8 on: December 17, 2021, 11:53:01 am »

    [/list]

    You need tell the DS1307 where you want to read from, also read again my post above on who generates the ack.

    To read seconds and minutes:
    1. Send a start sequence
    2. Send 0xD0, slave generates ack. (Yes, its a write command!)
    3. Send 0x00, the address of the seconds reg, slave generates ack.
    4. Send start sequence again, (restart)
    5. Send 0xD1, slave generates ack. (Now its a read command)
    6. Read seconds reg, master generates ack.
    7. Read minutes reg, master generates ack.
    8. Send stop sequence.
    Aren't you missing NAk at point 7 ? Master should be sent NAK after the last byte
     

    Offline woofy

    • Frequent Contributor
    • **
    • Posts: 334
    • Country: gb
      • Woofys Place
    Re: Message length when communicating with DS1307
    « Reply #9 on: December 17, 2021, 12:24:13 pm »

    Aren't you missing NAk at point 7 ?

    I am referring to who sends the ack. Yes, its a NACK at that point.
     
    The following users thanked this post: BlogRahul


    Share me

    Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
    Smf