DS1307 / I2C / CLOCK PROJECT

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
armagon29
Posts: 56
Joined: Thu May 07, 2009 4:40 pm
Been thanked: 2 times
Contact:

DS1307 / I2C / CLOCK PROJECT

Post 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

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post by Mikat »

Here is my macros for rtc,should work,but could have some bugs too..
Attachments
rtc macros.rar
(2.35 KiB) Downloaded 2844 times

armagon29
Posts: 56
Joined: Thu May 07, 2009 4:40 pm
Been thanked: 2 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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!!!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.

armagon29
Posts: 56
Joined: Thu May 07, 2009 4:40 pm
Been thanked: 2 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post by Dan81 »

Hello Armando

Try this file (which is not tested).

There 're some comments
Attachments
RTC-v2.fcf
a "little" bug with CH (reg0) in the previous version
(7.5 KiB) Downloaded 2203 times

armagon29
Posts: 56
Joined: Thu May 07, 2009 4:40 pm
Been thanked: 2 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post by Dan81 »

Hello Armando

I hope this new Flowchart will work better.

All the best

Daniel
Attachments
RTC-v3.fcf
still not tested
(12.15 KiB) Downloaded 2238 times

armagon29
Posts: 56
Joined: Thu May 07, 2009 4:40 pm
Been thanked: 2 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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
Attachments
RTC-v4.fcf
not tested
(10.5 KiB) Downloaded 1890 times

Spinnaay
Posts: 3
Joined: Sat Jan 09, 2010 4:56 pm
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post by Dan81 »

Hello

The same file with a little improvement.

Daniel
Attachments
RTC-v4b.fcf
tested on Matrix board v3.3
(16.14 KiB) Downloaded 2790 times

Spinnaay
Posts: 3
Joined: Sat Jan 09, 2010 4:56 pm
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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

flokulot
Posts: 1
Joined: Fri Oct 12, 2012 10:27 am
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post by Enamul »

Hi,
You can follow John's following post..you will get there everything.
http://www.matrixmultimedia.com/mmforum ... =29&t=8607
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
outlawstc
Posts: 32
Joined: Tue Oct 15, 2013 6:14 pm
Has thanked: 12 times
Been thanked: 9 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.
Attachments
DS1307 BASIC CLOCK DISPLAY.fcfx
(43.12 KiB) Downloaded 1670 times
"If your having code problems I feel bad for you son... I got 99 problems but a glitch ain't one"

burak
Posts: 5
Joined: Thu Jul 12, 2018 11:25 am
Has thanked: 2 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.
Attachments
DS1307InjectorTest.fcfx
(13.55 KiB) Downloaded 330 times
read ram 1.JPG
read ram 1.JPG (37.85 KiB) Viewed 20800 times
READ RAM.JPG
READ RAM.JPG (37.14 KiB) Viewed 20800 times

burak
Posts: 5
Joined: Thu Jul 12, 2018 11:25 am
Has thanked: 2 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post by burak »

in addition ;
Attachments
read ram .adress.JPG
read ram .adress.JPG (38.68 KiB) Viewed 20800 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: DS1307 / I2C / CLOCK PROJECT

Post 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.

Post Reply