Optimized Clock Engine
Kye
Posts: 2,200
Hey guys,
I just finished a spin·driver for the DS1307.
It features public methods for:
Getting/Setting the seconds on the DS1307,
Getting/Setting the minutes on the DS1307,
Getting/Setting the hours on the DS1307,
Getting/Setting the day on the DS1307,
Getting/Setting the date on the DS1307,
Getting/Setting the·month on the DS1307,
Getting/Setting the·year on the DS1307,
Turning the square wave output on (to a constant value which can be changed),
Turning the square wave output off (to a constant value which can be changed),
Getting/Setting the NVRAM on the DS1307,
The driver·has BCD to decimal conversion built in so that it returns decimal numbers for the time and can be·configured with decimal numbers for the time.
The driver has been completely optimized and features no bloat, the driver also includes idiot protection·which limits all method input parameters into their acceptable range.
Interface schematics for the I2C bus are included with driver as well as the ability to change the pins used for communication.
Enjoy!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
I just finished a spin·driver for the DS1307.
It features public methods for:
Getting/Setting the seconds on the DS1307,
Getting/Setting the minutes on the DS1307,
Getting/Setting the hours on the DS1307,
Getting/Setting the day on the DS1307,
Getting/Setting the date on the DS1307,
Getting/Setting the·month on the DS1307,
Getting/Setting the·year on the DS1307,
Turning the square wave output on (to a constant value which can be changed),
Turning the square wave output off (to a constant value which can be changed),
Getting/Setting the NVRAM on the DS1307,
The driver·has BCD to decimal conversion built in so that it returns decimal numbers for the time and can be·configured with decimal numbers for the time.
The driver has been completely optimized and features no bloat, the driver also includes idiot protection·which limits all method input parameters into their acceptable range.
Interface schematics for the I2C bus are included with driver as well as the ability to change the pins used for communication.
Enjoy!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
spin
29K
Comments
Just pass me the spec sheet, and I'll post the modified code here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
pretty close but not the same exactly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
I looked over the data sheet and it should have worked somewhat already with the DS1307 driver. Both have the same I2C setup.
Good luck,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod $50CAN has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module.
obj
oClock: "clockEngine"
pub main|hhh,mmm,sss
hhh:=oClock.getHours
mmm:=oClock.getMinutes
sss:=oClock.getSeconds
oD.PrintNum(0,7,0,hhh,2)
oD.PrintNum(20,7,0,mmm,2)
oD.PrintNum(40,7,0,sss,2)
i get a value of 165,165,165 printed to my screen any idea why?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod $50CAN has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module.
Question, are you using pull ups on both I2C pins? Its required here for the driver, it does not drive the I/O pins.
And, I can give you pointers if you would like on what parts of the driver do what but its not really complex. Fairly simply infact. If you want to reprogram it a little.
I already checked to make sure it runs the same way for acessing and such as the DS1307, so... I can't really say why it doesn't work for the DS1340.
Try setting the date and such first to make sure the clock is started and look at how you need to setup the real time clock as described in the manual. The DS1340 is not as simple as the DS1307.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod $50CAN has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH
Also, remember to configure the clock before reading from it first.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod $50CAN has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod $50CAN has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod $50CAN has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module.
Note that I programmed the driver to send not aknowledges and aknowledges automatically. So, you will need to modify the receiving and transmiting rountines or they will allow for only one byte at a time.
And, I would reconmend just making a spin processor and using the code as it is. I first tried to do this driver in asm and I found that it was a complete wates of one processor, and very flaky...
Better to just have one processor running the code in the background in spin.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
The name was something akin to asm I2C driver, do with it as you will or something. Note, that it was buggy....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
I am using the 1307 chip and find that every once in awhile I will get back 165 for all time/date values.· If I read it again the values come back 165 again then 2-3 reads later it is all fine again.· I am not sure if it is external noise (capacitative or not).· Do you have any insights into this.· I am basically troubleshooting a prototype and am dumping the values on the screen using tvout as I read them from the chip.
I am going to give your driver a try instead of the one I am currently using which was a general i2c driver that I modded to work with the 1307....
Tony
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
(The feature for bulk transfers is listed in the data sheet)
You just set the clock and let it run...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Need to make your prop design easier or secure? Get a PropMod has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
thank you for your driver! Just one question:
is it made by just changing the to variables at the beginning? I unfortunately connected the clock on pins 8 and 9, and don't wan't to produce a new board!
Thank you,
Max
I found this for Phillips suggestion on a level-shifter but I have seen people suggest just series resistors between the levels and pullups on either side.
http://www.nxp.com/news/backgrounders/bg_esc9727/
I'm writing a driver for the NXP PCF8583 and I came across your code for the 1307. Although they are fairly different animals for getting and setting I can make good use of your I2C code (fast for spin, I measured it at around 30KHz) and BCD conversions. Is there any particular way you would like me to credit that in the code? I plan to put the driver up on the exchange once complete. I have it mostly running right now, just need to get the year taken care of. It only does a 4 year count not the full 0-99 count of most clocks.