Hi Wen,
The first thing i'd suggest is stripping back to basics, and not trying to wrap up the functionality too soon. As you have not established reliable communication with the DS1306, it is not clear if the higher level tasks are failing because of basic protocol, or because of a program sequence error.
Can you also provide a schematic? Looking at the datasheet at :
http://datasheets.maxim-ic.com/en/ds/DS1306.pdf
It seems there is a pin called SERMODE that needs to configure the interface. It seem silly to ask but it is often the simple things that trip us up.
Also I notice in you code you set the mode to "0", i.e. CPOL = 0, CPHA = 0.
Page 11, Figure 5 says that CPOL for this part is "1", therefore your mode should be "2".
I dont have a DS1306 to hand, but you might consider using a program like this with some simple printf style debug, and basic operations.
http://mbed.org/users/chris/programs/DS1306/5zlv4/
Here I am simply clearing the WP bit for the RAM, then trying to write and read back from the RAM location. I've not read the data sheet in much detail, but it seems that if the hardware is powered up and SERMODE configured correctly, this should work, or at least get you a bit closer to the sort of thing that might help.
Good luck, let us know how you get on!
Cheers,
Chris
hello,everyone.
I use spi write and read data to DS1306(RTC). I want to use DS1306 control mbed on or off on right time.
but I can't get good result. I hope someone can help me.the question , I can't read the data which I set(write) before. why. here is my code result.
h:8 m:28 s:20
a_h:0 a_m:0 a_s:43
all data is not my set. s:20 always change.beause rtc run. here is my code.hope someone help me.
best wishes.