Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

DS1307 Real Time Clock


  • Please log in to reply
41 replies to this topic

#1 stacyh3

stacyh3

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 26 August 2010 - 10:15 PM

Attached is some code for using the DS1307 Real Time Clock chip via the I2C bus. The code includes a simple test application. Nothing facny, but it works. It also shows the use of extension methods which are pretty handy. The code comments include instructions on connecting the DS1307. Also, I scavanged an old ribbon cable and soldered one end to the SparkFun breakout board for the clock chip. I added pins to the other end to make is easy to use for prototyping. I figured that when I mounted this into a project box, it would be handy as well since it will allow easy access to the backup battery. Enjoy! Stacy

Attached Files



#2 StefanoZ

StefanoZ

    Member

  • Members
  • PipPip
  • 16 posts

Posted 13 December 2010 - 09:44 PM

Hi stacyh3,

good project. I used it and it works fine. I had to add two pullup resistors (one 2.2K between SDA and +5, one 2.2K between SCL and +5) as indicated in the ds1307 datasheet.

I used this module

Thank you for your project.

Bye,

Stefano.

#3 mrxer

mrxer

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationAustralia

Posted 22 December 2010 - 01:52 PM

Hi stacyh3,

good project. I used it and it works fine. I had to add two pullup resistors (one 2.2K between SDA and +5, one 2.2K between SCL and +5) as indicated in the ds1307 datasheet.

I used this module

Thank you for your project.

Bye,

Stefano.



How do i determine the address of the DS1307?

tony


#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 22 December 2010 - 01:57 PM

How do i determine the address of the DS1307?

According to the datasheet (pdf), the address is 0x68 (b1101000).

#5 mrxer

mrxer

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationAustralia

Posted 22 December 2010 - 02:39 PM

According to the datasheet (pdf), the address is 0x68 (b1101000).

thanks CW2....another question....

private const int I2CAddress = 0x68;
        private const int I2CTimeout = 1000;
        private const int I2CClockRateKhz = 100;

        public const int UserDataAddress = 8;
        public const int UserDataLength = 56;

        private I2CDevice clock = new I2CDevice(new I2CDevice.Configuration(I2CAddress, I2CClockRateKhz));

I have seen that i need to connect the DS1307 to Analog Pin 4 and 5. Is this hardcoded? The configuration does not specify which pins to use or are these the only ones that support i2c?

thanks in advance

tony


#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 22 December 2010 - 02:56 PM

I have seen that i need to connect the DS1307 to Analog Pin 4 and 5. Is this hardcoded? The configuration does not specify which pins to use or are these the only ones that support i2c?

Yes, it is hardcoded. You can see in the schematic that the I2C signal lines are multiplexed with analog inputs and accessible via Analog Input pins 4 and 5. The microcontroller has only one I2C hardware module - it would be possible to implement "software" I2C on any two pins, but it would require native driver; another option could be to use an expander or bus converter IC...

#7 mrxer

mrxer

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationAustralia

Posted 22 December 2010 - 03:08 PM

Yes, it is hardcoded. You can see in the schematic that the I2C signal lines are multiplexed with analog inputs and accessible via Analog Input pins 4 and 5. The microcontroller has only one I2C hardware module - it would be possible to implement "software" I2C on any two pins, but it would require native driver; another option could be to use an expander or bus converter IC...

Sorry for all the questions as i am using the code above but its not working. Do i need to connect a battery if it connect to 5V? When it gets to this code
public DateTime Now()
        {
            var data = new byte[7];
            int result = Read(0, data);//*******Returns 1 and data has all zeros in it

            //TODO: Add exception handling if result == 0

tony


#8 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 23 December 2010 - 01:39 AM

Sorry for all the questions as i am using the code above but its not working. Do i need to connect a battery if it connect to 5V?


The battery is backup in case the 5V is disconnected. If the battery is not present, this pin must be grounded or the DS1307 won't work... I found that out the hard way a few years ago...

#9 mrxer

mrxer

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationAustralia

Posted 23 December 2010 - 04:11 AM

Sorry for all the questions as i am using the code above but its not working. Do i need to connect a battery if it connect to 5V? When it gets to this code

public DateTime Now()
        {
            var data = new byte[7];
            int result = Read(0, data);//*******Returns 1 and data has all zeros in it

            //TODO: Add exception handling if result == 0

thanks for your advice..got it working...mmm...and also make sure your track don't touch each other. I am using a vero board and using screw driver to break tracks...drill might be better

tony


#10 Doctor Bit

Doctor Bit

    Member

  • Members
  • PipPip
  • 14 posts

Posted 12 October 2011 - 03:55 PM

Sorry for all the questions as i am using the code above but its not working. Do i need to connect a battery if it connect to 5V? When it gets to this code

public DateTime Now()
        {
            var data = new byte[7];
            int result = Read(0, data);//*******Returns 1 and data has all zeros in it

            //TODO: Add exception handling if result == 0

Me too... anybody find the solution? Thank You.
Alberto.

#11 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 12 October 2011 - 05:15 PM

Me too... anybody find the solution? Thank You.
Alberto.

how did you connect it? Did you include a 5V battery?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#12 Doctor Bit

Doctor Bit

    Member

  • Members
  • PipPip
  • 14 posts

Posted 14 October 2011 - 08:01 AM

how did you connect it? Did you include a 5V battery?

I connect the module:
SDA -> Netduino Analog Pin 4
SCL -> Netduino Analog Pin 5
GND -> Netduino GND
Vcc -> Netduino 5V

And also I connect 2 resistors (2.2 Khm):

SDA --> 2.2 Khm resistor --> Vcc
SCL --> 2.2 Khm resistor --> Vcc

And also include the CR2032 battery on the slot

But doesn't work... :(
P.S. I translate the C# code in VB...
Alberto.

#13 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 14 October 2011 - 08:45 AM

Alberto, have a peek at this thread.
Cheers
Biggest fault of Netduino? It runs by electricity.

#14 zelphia

zelphia

    New Member

  • Members
  • Pip
  • 6 posts

Posted 30 December 2011 - 08:13 PM

I have successfully run this demo software on a Netduino Plus. I used 1k pullup resistors to 3.3 volts for the I2C / Sq Wave pins. Powered the DS1307 with 5v. Changed '...Netduino' to ...'NetduinoPlus' at the top, and voila! The DS1307 came from SparkFun.

#15 boez52

boez52

    Member

  • Members
  • PipPip
  • 15 posts

Posted 09 October 2012 - 08:38 PM

I am trying to set the time of the RTC using a NTP server once a month. Any Ideas?

#16 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 November 2012 - 10:26 PM

Hi boez52,

I am trying to set the time of the RTC using a NTP server once a month. Any Ideas?

Are you struggling with getting the time from an NTP server...or setting the time of the RTC?

Chris

#17 boez52

boez52

    Member

  • Members
  • PipPip
  • 15 posts

Posted 04 November 2012 - 02:00 AM

Hi boez52,


Are you struggling with getting the time from an NTP server...or setting the time of the RTC?

Chris


Neither, I got it working a few weeks ago

#18 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 November 2012 - 02:16 AM

Neither, I got it working a few weeks ago

Okay cool. Sorry that I didn't see this post until today. Thank you for the update.

Chris

#19 upstream

upstream

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationBrasil

Posted 31 December 2012 - 07:24 PM

Hi.

Just to say this code worked fine to me after I set up clock. I was getting exceptions on mscorlib due weird values on DS1307. I think...

I used this code on Netduino plus, latest firmware and an Arduino module Tiny RTC with an extra AT24C32 memory on I2C bus, 3.3K ohms pull ups.

 

Many thanks!


"- Somewhere there's a bug to fix..."

#20 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 31 December 2012 - 07:43 PM

i also have written some ds1307 code.

it can be found here: http://forums.netdui...ground/?p=41558

 

it also shows how to access the ds1307 sram.

 

 

greetings






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.