PropBASIC - DS1307RTC
Rsadeika
Posts: 3,837
I guess the first question is, has anybody done this using PropBASIC? I just downloaded the data sheet for the Maxim chip, and reading the info. So far it looks like the PropBASIC I2C commands can be used to read the address, but the interesting part is getting the info that is stored there, and converting it to a readable form. I did not see any appropriate PropBASIC commands, that I recognized for doing this.
I am open to all suggestions as to the best approach for doing this.
Thanks
Ray
I am open to all suggestions as to the best approach for doing this.
Thanks
Ray
Comments
[noparse][[/noparse] Edit ] I found an SX/B program for the DS1307 -- it should give you some clues. Note, though, that one of the functions was written in Assembly. Here's the PropBASIC/PASM translation:
I ran this in a test program to confirm that it works.
[noparse][[/noparse] Edit ] A forum friend pointed out a redundant line in the routine -- it's gone now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 5/24/2010 1:05:52 AM GMT
Ray
You get the idea.
The key in migrating from one language to another -- even when they're similar -- is to learn to think in the new language. That way you're converting process instead of keywords (which don't always have direct translations, anyway).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 5/24/2010 1:57:16 PM GMT
Have a look at the following thread:
http://forums.parallax.com/forums/default.aspx?f=25&m=438391
I had the same question but about the PCF8593 RTC. I finally managed to work out the required I2C code and posted the code.
Good luck!
Helen
I suggest that you use this [noparse][[/noparse]WIP] approach when porting programs, instead of trying to do them in one big chunk. While encapsulating I2C routines in SUBs and FUNCs I came across a compiler bug with I2CWRITE (has been reported to Bean). This demo doesn't do any error checking via the ack/nak bit with I2CWRITE so I've disabled that option for the moment and the program runs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 5/24/2010 5:39:36 PM GMT
WR_DS1307 RTC_SEC, 0
WR_DS1307 RTC_MIN, 0
WR_DS1307 RTC_HR, 6
On the screen I get a constant 0e for the hours, and a number that changes every second that starts with a 6 which is supposed to be the minutes display, the seconds stays at 0 all the time. Does this reflect a problem with the FUNC BCD2DEC? I did not see where else it would be writing the 8 bit register on the 1307 chip.
Ray
Do you...
-- have the DS1307 hooked up correctly?
-- have pull-ups on SDA and SCL?
-- have the XI and XO pins (1 & 2) plugged into a breadboard? (see image above)
Honestly, I'm getting very close to keeping my PropBASIC code to myself; every time I hand a working demo to you, you say it's broken.
I just downloaded re-ran the original code; see attached.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 5/24/2010 7:30:39 PM GMT
Ray
The lesson I learned yesterday is that you have to be very careful with the circuits that you are working with. I am using a Propeller Platform (PP) board, and in this case a Futurlec DS1307 Mini-board. I disabled the 4.7 Ohm resisters on the Mini-board, and I was using pins 28,29 on the PP board, which have 10K resisters on line. The program compiled, and ran fine, but I was getting some unexpected results. My guess is that the on board EEPROM, on the PP board, and the DS1307 chip have the same address, the data was being clobbered. When I moved the Mini-board over to pins 27, and 26, enabled the 4.7 Ohm resisters, then I was getting the expected results, from the program.
I am going to have to be a lot more careful when working with the I2C buss, and related boards/parts. I think most assembled boards have a hard wired address, and they cannot be changed very easily, so this can be a challenge in terms of getting them all on the same buss. I think I have the correct understanding of I2C addressing?
Ray
I moved my DS1307 circuit over to the Propeller PDB so I could use the Propeller's EEPROM pins -- at first it didn't work with either Spin or PropBASIC. Every register read back as $FF. When it didn't work on different pins I concluded that the SDA line as not making a good connection and couldn't pull down the buss. That was the case and now the DS1307 is working on the same buss as the Propeller's EEPROM, and I've tested it in Spin and PropBASIC.
As with my first test, I suspect you're having a connections problem. On the Propeller, the SCL line is pin 28 and the SDA line is pin 29. It's easy to reverse these as the SDA pin on the DS1307 is 5 and the SCL is 6.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 5/25/2010 2:04:45 PM GMT
<edit> After looking at the PP board, I see that there is only one resister, cannot tell if it's on pin 29 or 28. Now I am wondering if both lines have to have a pull-up, in order for this to work correctly as a buss? <edit>
Ray
Post Edited (Rsadeika) : 5/25/2010 7:29:58 PM GMT
As you can see by the attached image, I plugged my DS1307 into the secondary socket of my Propeller Platform. Note that pins 1 - 3 of the DS1307 so not connect to the P/P circuitry (hardwired address for second EEPROM at %001). It works fine.
If you want to have one of those DS1307 modules drop shipped to me, I'll figure it out.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Ray
FWIW: We had exactly the same problem with the DS1302 Java code on the PPDB until adding proper pull-ups.
Driving I2C SCL for single-master operation is not a problem. Getting multi-master to *work at all* is always a problem[noparse]:)[/noparse]
--Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
May the road rise to meet you; may the sun shine on your back.
May you create something useful, even if it's just a hack.
Yes. I designed the Propeller Platform to have both, knowing that I would use my own I2C routines that don't drive SCL high.
That said, I looked into PropBASIC (PASM output) and the I2C commands -- like the Propeller -- do in fact drive the SCL line high and low. What this means is that you shouldn't need a pull-up on SCL. Since you have them on that board, it would be easy to add in; just connect the jumper.
I don't know if this will prove anything one way or another, but I've attached my Spin DS1307 test; it would be interesting to see if it works differently than PropBASIC on your clock module. You will need pull-ups on both SDA and SCL for my I2C object. Again, you can configure that right on your clock module.
BTW... you are powering your board from 3.3v, right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Ray
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Below I copied the portion that deals with voltages, according to the chart it supposed work with 5.0V, and 3.0V off of the attached battery. Now, the implication is that if it works off of a 3.0V battery, then it should work from a 3.3V source also.
RECOMMENDED DC OPERATING CONDITIONS
(TA = 0°C to +70°C, TA = -40°C to +85°C.) (Notes 1, 2)
PARAMETER SYMBOL CONDITIONS MIN TYP MAX UNITS
Supply Voltage VCC 4.5 5.0 5.5 V
Logic 1 Input VIH 2.2 VCC + 0.3 V
Logic 0 Input VIL -0.3 +0.8 V
VBAT Battery Voltage VBAT 2.0 3 3.5 V
Ray
Ray
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Ray