Page 1 of 1

DS1307 / I2C / CLOCK PROJECT

Posted: Thu May 14, 2009 4:06 pm
by armagon29
Dear All:

I needs some hel with this project, I want to build a simple clock using a time chip (DS1307 :?: ) but this is my first time using a I2C protocol and I don’t know how to set time and date, and before to do that, read and show into to LCD each second, If someone can explain me how, or / if some who can send me a similar example, may it help me a lot

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Fri May 15, 2009 10:09 am
by Mikat
Here is my macros for rtc,should work,but could have some bugs too..

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Mon May 18, 2009 5:57 am
by armagon29
Dear All:

Tanks for this example of macros, but this example is a little bit complicate, Can someone send me an example not complicate

Please!!!

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Mon May 18, 2009 8:59 am
by Benj
Hello

I2C comms is actually fairly simple once you know the structure of the communication,

This is taken from the I2C component help file.

Sending Data
Output a start condition //Starts the device listening to the IΒ²C bus.
Transmit the External Device address with the LSb cleared. //Enables the device and sets to write mode.
Transmit the Internal address. //Sets the address to start writing data to.
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached
....
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached
Output a stop condition //Stops the device listening to the IΒ²C bus.

Note. When writing to a page of memory make sure to only write within that page as if you carry on writing bytes the internal address will wrap around and begin overwriting the first bytes.

Receiving Data
Output a start condition //Starts the device listening to the IΒ²C bus.
Transmit the External Device address with the LSb cleared. //Enables the device and sets to write mode.
Transmit the Internal address. //Sets the address to start reading data from.

Output a restart condition //Restarts the device listening to the IΒ²C bus.
Transmit the External Device address with the LSb set. //Enables the device and sets to read mode.
Receive a byte of data with last byte 0. //Device will send data and increment internal address until page limit is reached
....
Receive a byte of data with last byte 1. //Device will send data.
Output a stop condition //Stops the device listening to the IΒ²C bus.

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Fri May 29, 2009 2:56 am
by armagon29
Dear Benj:


Thanks for your help, but it is a little confuse for me, really I don’t have a formal education on Pic, I am a simple hobbits that wants to learn more about pics, I not sure how to fill the box in the options to start, sent and receive and others options, this is the reason to look for a example to do this, could you help me to fill an example please¡¡¡¡¡, I saw some information on the datasheet but I still doves

devise address= %11010000

Armando Gonzalez

Receiving Data
Output a start condition //Starts the device listening to the IΒ²C bus. OK
Transmit the External Device address with the LSb cleared. //Enables the device and sets to write mode. How'????
Transmit the Internal address. //Sets the address to start reading data from. How????

Output a restart condition //Restarts the device listening to the IΒ²C bus. OK
Transmit the External Device address with the LSb set. //Enables the device and sets to read mode. How ?????
Receive a byte of data with last byte 0. //Device will send data and increment internal address until page limit is reached
....
Receive a byte of data with last byte 1. //Device will send data.
Output a stop condition //Stops the device listening to the IΒ²C bus.

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Fri May 29, 2009 8:33 am
by Benj
Hello Armando

The device address is what I referred to as the external device address.

Transmit the External Device address with the LSb cleared. //Enables the device and sets to write mode. How'????


Your device address is 208 in decimal when the LSb is cleared. Simply use the transmit byte macro.

Transmit the Internal address. //Sets the address to start reading data from. How????


Again use the transmit byte macro. For large EEPROMS etc with two (16-bit) address variables you will have to send two bytes here instead of one.

Transmit the External Device address with the LSb set. //Enables the device and sets to read mode. How ?????


Your device address is 209 in decimal when the LSb is set.

Hope this helps.

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Fri May 29, 2009 8:41 am
by Benj
From looking at the datasheet it seems possible to simply do the following to read the contents of the device without having to do the start restart functionality.

Receiving Data
Output a start condition //Starts the device listening to the IΒ²C bus. OK

Transmit the External Device address with the LSb set. //Enables the device and sets to read mode.
Receive a byte of data with ack = 0. //Device will send data and increment internal address until page limit is reached
....
Receive a byte of data with ack = 1. //Device will send data.
Output a stop condition //Stops the device listening to the IΒ²C bus.

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Fri May 29, 2009 8:27 pm
by Dan81
Hello Armando

Try this file (which is not tested).

There 're some comments

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Thu Jun 04, 2009 4:49 am
by armagon29
Dear Sir:
I tested the program sent by you, but I’m afraid that it does not work, the lcd display 45:85:85 , A0 reset seconds, but not time (hr,min, sec) are displayed
Thanks for your help

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Sat Jun 06, 2009 6:45 pm
by Dan81
Hello Armando

I hope this new Flowchart will work better.

All the best

Daniel

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Sun Jun 07, 2009 4:01 am
by armagon29
Dear Sir:

New file works excellent, thanks, but I have some questions

a)Why LCD show only 1 digits for the first 9 seconds this means for example,
5 seconds = xx:xx:05, but only 5 was displayed by the LCD; xx:xx:5

b)Is it possible to show at the same time the time and date ?(date, month and year)

c)Could you be so kindle to explain me what is happening into program, a little brief, please
Thanks again

Armando

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Sun Jun 07, 2009 8:55 am
by Dan81
Hello Armando

a) It's normal , you must add a condition (see file).

b) take a look at the DS1307 datasheet (http://datasheets.maxim-ic.com/en/ds/DS1307.pdf)
see table2 (p8) "timekeepers registers" .

c)
- Macros : "SQW" or "Reser Sec" : show you how to write into a register.
- Macros : "Read time" : show how to read one or more (consecutive) registers.

Reading a register is a bit special because you must "point at " the register that you want to read otherwise you don't know which register you are reading.

See figure 4, 5 and 6 page 13,14 ( they are very useful)

Daniel

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Sun May 02, 2010 10:14 am
by Spinnaay
Hi Everyone.

Dan, you're example files don't open for me. I get 'Unexpected File Format.'

I am running Flowcode v3.6.11.53

Thanks for your help.

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Sun May 02, 2010 6:56 pm
by Dan81
Hello

The same file with a little improvement.

Daniel

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Tue May 04, 2010 4:55 pm
by Spinnaay
Thanks Dan.

That's perfect. I've had a good read and it all makes sense! Now i've got to try and add my own bits so I can change the time. Should be ok using your code as a starting point.

Thanks

Thom

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Fri Oct 12, 2012 10:33 am
by flokulot
hello guys.. please help me about DS1307 rtc. i am having problem in coding rtc. i am new to flowcode and i am using PIC167f877a.

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Fri Oct 12, 2012 10:59 am
by Enamul
Hi,
You can follow John's following post..you will get there everything.
viewtopic.php?f=29&t=8607

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Tue Oct 15, 2013 7:03 pm
by outlawstc
Here is The same flowchart with some added stuff such as setting the time and date to the RTC.. I also changed the way it all prints to the lcd.. I made it where it only prints the date info at midnight. .. I don't like the flicker of the refresh rate. It is more noticeable when the whole screen refreshes every second. .. Less noticeable when only the time refreshes .. Then I added a interrupt and used the RTC 1hz square wave output to trigger the lcd print of the time... it makes it where you don't have to add a delay in the main loop.. also one more thing... I made it where it prints the days full name like "monday" ,"tuesday", etc instead of a single letter to represent the day :D.. Im using a 20x4 lcd.

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Thu Oct 11, 2018 11:47 am
by burak
Hi Everyone ,

I have some questions about DS1307 example code .

1-Representation of Hex number and Byte numbers. 'READ RAM' figure ( is taken from example code

-Read a byte from RAM -
RAMbyte=ReadRam(16) question1 : Is 16 decimal number ?

2-In 'READ RAM1' figure

Address / bayt / 16 --- question2 16 is assigned to Address variable ? ISN'T İT ?

3-'In read Ram .Adress ' figure ,

I2C_Master1::TransmitByte(.Address) ---question3: I did'n understand representation of '.Adress ' ?

3.a) means of dot (.) before 'Adress' ?
3.b).Address makes decimal to hex conversion ?

decimal 16 -- hexadecimal 0010H . ?

Please explain.

Thank you.

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Thu Oct 11, 2018 11:48 am
by burak
in addition ;

Re: DS1307 / I2C / CLOCK PROJECT

Posted: Fri Oct 12, 2018 9:48 pm
by Benj
Hello Burak,

question1 : Is 16 decimal number ?


Yes 16 is decimal, a hex number should be indicated with 0x e.g. 0x10 would be = 16

This is not always the case so it's right to be cautious but in Flowcode 0x is hexadecimal and 0b is binary.

question2 16 is assigned to Address variable ? ISN'T İT ?


Yes the literal or variable value you pass will be used as the address of the RAM location to read.

3.a) means of dot (.) before 'Adress' ?
3.b).Address makes decimal to hex conversion ?


A dot in front of a variable name indicates a local variable or parameter, i.e. a variable that only exists within the given macro. As opposed to a global variable that exists throughout the program which do not have dots in front of their name.

In this case the parameter .Address is given the decimal value 16.