DS1307 / I2C / CLOCK PROJECT
DS1307 / I2C / CLOCK PROJECT
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
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
-
- 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
Here is my macros for rtc,should work,but could have some bugs too..
- Attachments
-
- rtc macros.rar
- (2.35 KiB) Downloaded 2887 times
Re: DS1307 / I2C / CLOCK PROJECT
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!!!
Tanks for this example of macros, but this example is a little bit complicate, Can someone send me an example not complicate
Please!!!
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: DS1307 / I2C / CLOCK PROJECT
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.
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.
- 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
Hello Armando
The device address is what I referred to as the external device address.
Hope this helps.
The device address is what I referred to as the external device address.
Your device address is 208 in decimal when the LSb is cleared. Simply use the transmit byte macro.Transmit the External Device address with the LSb cleared. //Enables the device and sets to write mode. 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 Internal address. //Sets the address to start reading data from. How????
Your device address is 209 in decimal when the LSb is set.Transmit the External Device address with the LSb set. //Enables the device and sets to read mode. How ?????
Hope this helps.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Dan81
- 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
Hello Armando
Try this file (which is not tested).
There 're some comments
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 2245 times
Re: DS1307 / I2C / CLOCK PROJECT
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
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
- Dan81
- 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
Hello Armando
I hope this new Flowchart will work better.
All the best
Daniel
I hope this new Flowchart will work better.
All the best
Daniel
- Attachments
-
- RTC-v3.fcf
- still not tested
- (12.15 KiB) Downloaded 2283 times
Re: DS1307 / I2C / CLOCK PROJECT
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
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
- Dan81
- 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
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
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 1938 times
Re: DS1307 / I2C / CLOCK PROJECT
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.
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.
- Dan81
- 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
Hello
The same file with a little improvement.
Daniel
The same file with a little improvement.
Daniel
- Attachments
-
- RTC-v4b.fcf
- tested on Matrix board v3.3
- (16.14 KiB) Downloaded 2841 times
Re: DS1307 / I2C / CLOCK PROJECT
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
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
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.
- 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
Hi,
You can follow John's following post..you will get there everything.
http://www.matrixmultimedia.com/mmforum ... =29&t=8607
You can follow John's following post..you will get there everything.
http://www.matrixmultimedia.com/mmforum ... =29&t=8607
- 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
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 .. Im using a 20x4 lcd.
- Attachments
-
- DS1307 BASIC CLOCK DISPLAY.fcfx
- (43.12 KiB) Downloaded 1713 times
"If your having code problems I feel bad for you son... I got 99 problems but a glitch ain't one"
Re: DS1307 / I2C / CLOCK PROJECT
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.
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 373 times
-
- read ram 1.JPG (37.85 KiB) Viewed 21733 times
-
- READ RAM.JPG (37.14 KiB) Viewed 21733 times
Re: DS1307 / I2C / CLOCK PROJECT
in addition ;
- Attachments
-
- read ram .adress.JPG (38.68 KiB) Viewed 21733 times
- 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
Hello Burak,
This is not always the case so it's right to be cautious but in Flowcode 0x is hexadecimal and 0b is binary.
In this case the parameter .Address is given the decimal value 16.
Yes 16 is decimal, a hex number should be indicated with 0x e.g. 0x10 would be = 16question1 : Is 16 decimal number ?
This is not always the case so it's right to be cautious but in Flowcode 0x is hexadecimal and 0b is binary.
Yes the literal or variable value you pass will be used as the address of the RAM location to read.question2 16 is assigned to Address variable ? ISN'T İT ?
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.3.a) means of dot (.) before 'Adress' ?
3.b).Address makes decimal to hex conversion ?
In this case the parameter .Address is given the decimal value 16.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel