@photomankc - Ah, well, just put in a special thanks section for my I2C code and BCD conversion code. I belive you cannot optimize it more than I have done without more complex techniques.
@propwell - You understanding is dead on. You'll find my driver have been purposefully made to be as novice/idiot proof as possible as I am writing them for high school students. Simply change the pin names and all is good. Also, the DS1307 can just directly connect to the props I/O lines. So Life is easy.
Also, do you guys like the timing functions included in the driver? They are pretty nice as they have a resolution up to 2^31 of milliseconds or seconds and they loose no accuracy relative to the clock.
@Kye - Will do. My code will not be quite as tight as yours but I can work on that. Having to unpack two and three values from the same register is a pain. I was really impressed by the speed of the I2C spin code. I've been used to about 23KHz even at 100MHz with other more generic spin objects, but with this I'm getting 30+ KHz accourding to my scope at 80MHz clock so pretty nice. I'm figuring that could reach up close to 36KHz on my 100MHz boards.
Um, try the code that I put up in the first post vs the code in the obex. Maybe I broke something with all the updates. I don't know however as it works on my end and no ones has complained.
Everything looks like it should work. Are you sure there aren't any other problems?
Also note that the driver uses opendrain mode to communicate so if you are driving the outa ports on those pins nothing will function. The I2C code should be the only thing running on those ports.
Maybe the voltage isn't going low enough? IDK, try a bunch of stuff. I doubt its the driver.
Why do you have series resistors if you are only pulling the SCL and SDA lines to 3.3V?· Looks like that would create a voltage divider that would raise the floor on the bus' 0 state·by a 150mV or so.· Doubt that's the root cause but it doesn't make sense to me either.· I'd try the BasicI2C driver and just test to see if you get a hit from "DevicePresent" on the clock address.· At least then you know the bus works.
Propeller not have open colector outputs and if You connect that lines directly You can have casses that You drive lines 3.3V from prop and Slave drive lines to GND -- Not good.
I use 100R to 150R as serie resistors in that casses
Regards ChJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Nothing is impossible, there are only different degrees of difficulty. For every stupid question there is at least one intelligent answer. Don't guess - ask instead. If you don't ask you won't know. If your gonna construct something, make it·as simple as·possible yet as versatile as posible.
I see what you are saying but if you have pull-ups on both lines then you shouldn't need to drive 3.3V on the bus anyway and as I understood it you should never do that on the SDA line. The driver Kye wrote does not drive SCL from what I see, it just toggles between low and input. Anyway it's probably a moot issue I doubt that is causing his issues here.
propwell,
165 means your code is seeing all ones on bus and the BCD conversion code in the driver is returning 150 + 15 since %1111 = 15. When I first started playing with my NXP RTC I had the same issue and it came down to the fact my address was wrong. What do you have for RTC_Address in the driver code and what does the Data Sheet say the address is? Make sure your SCL and SDA lines are what you think they are and not crossed too.
I have not looked in that code.
But You can see it as semi-open colector circuit. That Reguire PULL upp·obviously else SCA/SD lines on Slave side can't decide treshold of 1 state.
BUT still You reguire serie resistors for worst casse scenario.
In Yours casse look if You have correct Values of Pull upp resistors 4.7-10K. I had problems some times width bad resistors on Pull upp.
In both casses if it is to small else brocen You can have communications problem betwen IC's
Sorry my bad English
Regards
ChJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Nothing is impossible, there are only different degrees of difficulty. For every stupid question there is at least one intelligent answer. Don't guess - ask instead. If you don't ask you won't know. If your gonna construct something, make it·as simple as·possible yet as versatile as posible.
i'm getting on with my RTC-project!
When i don't use the battery, and connect the V_Bat-Pin to Ground, it works!!
But when i connect V_Bat with the battery (3V), i get he 165s again!
I'm not sure, but do i have to set the NVRAM anyhow?
That's the code i use at the moment:
hi kye,
hm strange.. so i don't have to start the RTC in a special way? Just run the programm with "setSeconds" and all these functions, and the RTC keeps the time?
Um, you have to set the seconds first so that the RTC begins to count. Check the data sheet on the ds1307 and look at the oscilator enable bit. I belive my software sets it to run after calling set seconds, but maybe something has changed in your setup.
So, try setting all of the date values first with the battery attached and then polling for the time.
Comments
@propwell - You understanding is dead on. You'll find my driver have been purposefully made to be as novice/idiot proof as possible as I am writing them for high school students. Simply change the pin names and all is good. Also, the DS1307 can just directly connect to the props I/O lines. So Life is easy.
Also, do you guys like the timing functions included in the driver? They are pretty nice as they have a resolution up to 2^31 of milliseconds or seconds and they loose no accuracy relative to the clock.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Take a look at the code posted for faster I2C for EEPROM.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
But i still can't connect to the RTC!
Attached is my schematics and now the code i use:
But all i get is a "165"!
Thank you,
Max
Everything looks like it should work. Are you sure there aren't any other problems?
Also note that the driver uses opendrain mode to communicate so if you are driving the outa ports on those pins nothing will function. The I2C code should be the only thing running on those ports.
Maybe the voltage isn't going low enough? IDK, try a bunch of stuff. I doubt its the driver.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Propeller not have open colector outputs and if You connect that lines directly You can have casses that You drive lines 3.3V from prop and Slave drive lines to GND -- Not good.
I use 100R to 150R as serie resistors in that casses
Regards ChJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
For every stupid question there is at least one intelligent answer.
Don't guess - ask instead.
If you don't ask you won't know.
If your gonna construct something, make it·as simple as·possible yet as versatile as posible.
Sapieha
I see what you are saying but if you have pull-ups on both lines then you shouldn't need to drive 3.3V on the bus anyway and as I understood it you should never do that on the SDA line. The driver Kye wrote does not drive SCL from what I see, it just toggles between low and input. Anyway it's probably a moot issue I doubt that is causing his issues here.
propwell,
165 means your code is seeing all ones on bus and the BCD conversion code in the driver is returning 150 + 15 since %1111 = 15. When I first started playing with my NXP RTC I had the same issue and it came down to the fact my address was wrong. What do you have for RTC_Address in the driver code and what does the Data Sheet say the address is? Make sure your SCL and SDA lines are what you think they are and not crossed too.
I have not looked in that code.
But You can see it as semi-open colector circuit. That Reguire PULL upp·obviously else SCA/SD lines on Slave side can't decide treshold of 1 state.
BUT still You reguire serie resistors for worst casse scenario.
In Yours casse look if You have correct Values of Pull upp resistors 4.7-10K. I had problems some times width bad resistors on Pull upp.
In both casses if it is to small else brocen You can have communications problem betwen IC's
Sorry my bad English
Regards
ChJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
For every stupid question there is at least one intelligent answer.
Don't guess - ask instead.
If you don't ask you won't know.
If your gonna construct something, make it·as simple as·possible yet as versatile as posible.
Sapieha
Post Edited (Sapieha) : 10/23/2009 2:22:09 PM GMT
No problem.... I understand what you are saying.
i'm getting on with my RTC-project!
When i don't use the battery, and connect the V_Bat-Pin to Ground, it works!!
But when i connect V_Bat with the battery (3V), i get he 165s again!
I'm not sure, but do i have to set the NVRAM anyhow?
That's the code i use at the moment:
with battery, i get:
and without:
any ideas?
Thank you very much!
Max
I do not understand why this would not work correctly. Maybe the chip you are using is bad or something.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
hm strange.. so i don't have to start the RTC in a special way? Just run the programm with "setSeconds" and all these functions, and the RTC keeps the time?
Thank you,
Max
So, try setting all of the date values first with the battery attached and then polling for the time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,