• AVR Freaks

Helpful ReplyHot!DS1307 Data Transfer on I2C Serial Bus

Author
abhi143
Starting Member
  • Total Posts : 69
  • Reward points : 0
  • Joined: 2018/05/20 09:06:52
  • Location: 0
  • Status: offline
2019/10/24 04:00:39 (permalink)
0

DS1307 Data Transfer on I2C Serial Bus

I am looking a simple guide that explains about DS1307  and how to interface it with PIC16f877a. I don't understand the timing diagram in the datasheet I am trying to know how master write data to DS1307 ?
 
Thanks 
 

Attached Image(s)

#1
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/24 04:31:15 (permalink)
+1 (1)
Have you ever worked with I2C at all?
There's plenty of application notes on the Microchip website.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#2
Bob White
Super Member
  • Total Posts : 265
  • Reward points : 0
  • Joined: 2010/11/06 19:52:38
  • Location: Denver, Colorado
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/24 09:31:32 (permalink)
+1 (1)
Start by studying this document:

https://www.nxp.com/docs/en/user-guide/UM10204.pdf
#3
ALostCause12
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/08/28 13:14:02
  • Location: 0
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/24 15:29:38 (permalink)
0
I2C is extremely standardized, and based on your question I am assuming you are looking to just get an interface up and running between the PIC16f877a and the RTC in question. The mcu you are using has an MSSP module which is readily configurable in MCC within the MPLABX IDE. The only info you really need is the slave and data registers you need to write to and indeed, an understanding of I2C of which there are plenty of resources.
 
I think this tutorial will be of use to you: https://microchipdeveloper.com/xpress:how-to:on-board-temperature-sensor
 
 
#4
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/24 15:38:26 (permalink)
+1 (1)
ALostCause12
...
The mcu you are using has an MSSP module which is readily configurable in MCC within the MPLABX IDE.

MCC doesn't want to know about old PICs like the PIC16F877A.
You could use it to generate code for a newer PIC16F device, but the MSSP may not be fully compatible with the 877A version.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#5
abhi143
Starting Member
  • Total Posts : 69
  • Reward points : 0
  • Joined: 2018/05/20 09:06:52
  • Location: 0
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/25 12:20:32 (permalink)
0
ric
Have you ever worked with I2C at all?
There's plenty of application notes on the Microchip website.

I haven't worked yet 
I am reading datasheet DS1307 I don't understand what are data (n+1)--  Data (n+x) in datasheet

Attached Image(s)

#6
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/25 13:51:00 (permalink) ☄ Helpfulby abhi143 2019/10/26 00:59:32
+1 (1)
abhi143
...
I am reading datasheet DS1307 I don't understand what are data (n+1)--  Data (n+x) in datasheet

That simply means, when you are sending multiple bytes of data to the chip, the first byte (n), the second byte (n+1), and so on. It's a trivial point.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#7
Mysil
Super Member
  • Total Posts : 3473
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/25 16:12:30 (permalink) ☄ Helpfulby abhi143 2019/10/26 00:59:22
0
Hi,
There are several different ways possible.
Code and examples that was suggested when PIC16F877A was recommended products,
have been removed from recent versions of XC8 compiler and example codes.
 
There have been several threads about I2C master code for various devices in these forum.
One is here, https://www.microchip.com/forums/FindPost/982099
with example code for some devices, but no RTCC among the slaves.
 
For I2C in Master mode, the MSSP module in PIC16F877 work the same as all later PIC16F1xxx devices.
Some PIC devices have 1 MSSP peripheral, and other devices have 2.
Code generated by MCC for a supported PIC16F1xxx device may be modified and used for 16F877A.
Mikro-E Clicks library in MCC may make example code for MCP79410 Real-Time Clock and Calendar, 
which is similar to DS1307.
 
    Mysil
 
#8
abhi143
Starting Member
  • Total Posts : 69
  • Reward points : 0
  • Joined: 2018/05/20 09:06:52
  • Location: 0
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/26 00:59:07 (permalink)
0
ric
abhi143
...
I am reading datasheet DS1307 I don't understand what are data (n+1)--  Data (n+x) in datasheet

That simply means, when you are sending multiple bytes of data to the chip, the first byte (n), the second byte (n+1), and so on. It's a trivial point.




Master send the Slave address + 0 , The master then transmits word address, then the master generates the ACK and NACK and if master get NACK,  send stop condition  and If get ACK it wants another byte
Master send word address , generate ACK/NACK
if ACK
Master send repeated start with read and generate ACK/NACK
if ACK
 
We can use for loop to read the n bytes  also we can store multiple bytes into int array
 
My question  How to read multiple bytes of data.?
#9
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: DS1307 Data Transfer on I2C Serial Bus 2019/10/26 03:36:47 (permalink)
0
abhi143
Master send the Slave address + 0 , The master then transmits word address, then the master generates the ACK and NACK

No, the Slave generates the ACK or NACK at that point.
 

and if master get NACK,  send stop condition 

Yes, because that means the Slave is not responding, so give up and end the whole operation.
 

and If get ACK it wants another byte

That is badly worded. An ACK means the Slave recieved the address correctly. It is up to the Master what happens next.

Master send word address , generate ACK/NACK
if ACK

Huh. You already sent the address.

Master send repeated start with read and generate ACK/NACK

Yes, you send repeated start, and the read address, but it is the Slave then generates the ACK if it is wirking.
 

We can use for loop to read the n bytes  also we can store multiple bytes into int array
My question  How to read multiple bytes of data.?

THIS is where an ACK or NACK from you makes a difference.
After receiving each byte, you send ACK if you want more, or NACK if you are done.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#10
Jump to:
© 2019 APG vNext Commercial Version 4.5