ds1307

Forum for problems or queries regarding Flowcode Comms Components. Eg LIN, I2C, SPI, RS232, CAN, IrDA etc

Moderators: Benj, Mods

Post Reply
stevel
Posts: 19
Joined: Sat Sep 05, 2009 2:18 pm
Contact:

ds1307

Post by stevel »

Hi can someone look at this file please its not working. i have had flowcode for 11 months and not any projects done yet.
I am getting a bit stressed by now. :x
Attachments
DS130_777.fcf
(6 KiB) Downloaded 612 times

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

Post by Dan81 »

Hello Stevel

Your last icon is : "LCD Display : PrintString (string)"
If you want to see the received data the last icon must be :
"LCD Display : PrintNumber (Retval)".

About your second post
bit 7 of register 0 is Clock Halt, it must be "0" .

Daniel

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

Post by Benj »

Hello Stevel,

Please do not double post. You have created two forum posts with the same title "ds1307". Double posting is a big no no and may get you banned from the forum.

Also you cannot blame other forum users for your stress. If you need help with specific problems then why not detail the problems your having in full. Doing so may help you to understand what is going wrong rather then simply saying help me im stuck and I've given up.

stevel
Posts: 19
Joined: Sat Sep 05, 2009 2:18 pm
Contact:

Re: ds1307

Post by stevel »

i have been able to read and write to a ds1307 can someone tell me how to display hh/mm/ss on 7segment display as i am not sure how to start my code. can someone list steps i have to do so that i can do this

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

Post by Dan81 »

hello Stevel

My flowchart reads DS1307 and displays on LCD.
(DS1307 is not initialised : Clock Halt , time and date)

Daniel
Attachments
RTC_disp_TIME_FC3.fcf
(11.72 KiB) Downloaded 707 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

Post by Benj »

There are also some good examples of controlling the 7segment displays in the Flowcode examples download available from the Flowcode CD or the main Flowcode product page.

gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time
Contact:

Re: ds1307

Post by gggwww »

Dan81,

In your DS1307 example how it the DS1307 initialized with the correct time - how is it set?

Thanks !!

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

Post by Dan81 »

Hello

The DS1307 is not initialized in my example.

If you want to initialize it yourself ( and the RTC keeps the right time thanks to the battery).
see the attached file.
Load my file, reset the pic at the right hour then load your program.
(My DS1307 is an "homemade" Eblock)
The file is not tested on hardware but the simulation with Proteus is OK.

If the DS1307 is to be intialized by the user , it's little bit longer.


Daniel
Attachments
init_time.fcf
not tested on hardware
(11.93 KiB) Downloaded 591 times

gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time
Contact:

Re: ds1307

Post by gggwww »

Daniel,

It looks like the attached program is complete - init time and then time display

Can I load the program with init enabled ( time settings like like they are HEX) and then after initial run on the PIC , reload with the init call disabled so it does not continually reset the time

Also, which pin on the 887 are you using for the I2C Data Line?

Also, I am using V4 of flowcode

I greatly appreciate your efforts - I have been looking for a good I2C program to learn from and this may be it - always good to start with an excellent example.

Best Regards

George

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

Post by Dan81 »

Hello George

Macro "init time" can be selected at the beginning with an "init" switch (see attached file).

I2C is "hardware" (I use hardware as much as I can)
For 16F887 SCK is RC3 and SDA is RC4. (don't forget the pull up (4.7k))

If you use Flowcode v4 , post on Flowcode v4 forum .
Now, I prefer to use v4.

Daniel
Attachments
init_time_v2.fcf
not tested
(12.18 KiB) Downloaded 507 times

gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time
Contact:

Re: ds1307

Post by gggwww »

Daniel,
I will give this a try - will let you know how things go.
Thank you very much !!
Best Regards,
George

gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time
Contact:

Re: ds1307

Post by gggwww »

Daniel,

Wired up everything and loaded the 887 with your V2 code. Getting 00:00:00 on the LCD - not changing. In your code was the CH bit set properly? This is from the DS1307 datasheet

Bit 7 of Register 0 is the clock halt
(CH) bit. When this bit is set to 1, the oscillator is disabled. When cleared to 0, the oscillator is enabled. On first
application of power to the device the time and date registers are typically reset to 01/01/00 01 00:00:00
(MM/DD/YY DOW HH:MM:SS). The CH bit in the seconds register will be set to a 1. The clock can be halted
whenever the timekeeping functions are not required, which minimizes current (IBATDR).

Could this be why the closk is not advancing?

Thanks,
George

gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time
Contact:

Re: ds1307

Post by gggwww »

Daniel,

Just as a check I put a frequency counter on the DS1307 Oscillator and the Oscillator is not running so the CH bit may not be set to 0.

I dont fully understand your code so any help on this would be greatly appreciated.

Regards,

George

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

Post by Dan81 »

Hello George

Did you push "A0" the first time? When SECOND is set , bit CH is set to 0.

Try "init_time_v3", you'll see a 1second square wave on SQW/OUT (pin 7).
you can put a LED with a pull up on SQW/OUT during debug.

If LCD still locked, take a look at (with an oscilloscope or with Flowcode) the acknowlegde bit, it must be at 0.

Can you post your schematic ?

Daniel
Attachments
init_time_v3.fcf
(12.22 KiB) Downloaded 481 times

gggwww
Posts: 54
Joined: Wed Sep 09, 2009 12:50 am
Has thanked: 1 time
Contact:

Re: ds1307

Post by gggwww »

Daniel,

Thanks for the quick response

Please find the schematic attached - hopefully all is legible

I tried a dirrerent DS1307 and same result - I really want to get this working - thanks for your help !!

George
Attachments
Picture.jpg
(166.55 KiB) Downloaded 6375 times

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

Post by Dan81 »

Hello George

SQW/OUT needs a pull up.
But if bit CH is still at 1, there will be nothing on SQW.

- Take a look at SCL and SDA with an oscilloscope. (The idle state must be 1.)
If there is no aknowledge, the read value is 255 (and display 45 or 85) and you get 00
Did you modify the value of the init time (init_min ...) ?


good luck

Daniel

stevel
Posts: 19
Joined: Sat Sep 05, 2009 2:18 pm
Contact:

Re: ds1307

Post by stevel »

Can i have help / how do you put in a switch to alter the seconds to count up then set the clock ticking
Attachments
init_time_v2.fcf
(12.18 KiB) Downloaded 448 times

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

Post by Dan81 »

Hello Steve

I see 2 solutions

read Switch
if Switch = 1 then
read SEC (already done)
SEC = SEC - 1 ( warning SEC must be >= 0)
write SEC

OR

read Switch
if Switch = 1 then CH = 1 else CH=0
( CH : Clock Halt, bit 7 of SECond register)
You must read SEC then masking (CH=1 : SEC = SEC OR 0x80 ; CH =0 : SEC = SEC AND 0x7F) and writing SEC

(I think this macro must be in the "Init" macro but not in the main loop. But it depends on what you want to do)

Daniel

stevel
Posts: 19
Joined: Sat Sep 05, 2009 2:18 pm
Contact:

Re: ds1307

Post by stevel »

I am not understanding what to do can you please explain to me in detail please or please alter the file for me and i will try to then to alter the hours and mins.
Regards Stephen.

stevel
Posts: 19
Joined: Sat Sep 05, 2009 2:18 pm
Contact:

Re: ds1307

Post by stevel »

i am new to flowcode aswell not understanding it / i find it difficult to use as i have no proggraming skills at all

stevel
Posts: 19
Joined: Sat Sep 05, 2009 2:18 pm
Contact:

Re: ds1307

Post by stevel »

can someone help me out
I have got as far as using a switch on port a of micro and counting/ but what do i do to make this switch alter the seconds on a ds1307. do i just do a count to 59 and sent it to the seconds reg on a ds1307/ or do you do this another way. i am not sure how to go on about this.

Post Reply