Asm I2C driver for various stuff... Do with it as you will.
Kye
Posts: 2,200
Hey guys,
I spent some time working on a asm I2C driver for my propeller project. But after some redesigning of the project I have decided to drop it from my plans.
So... to put the code to good use I'll be posting it on the object exchange, the driver comes with some rountines to make a RTC (DS1307)·work. It does not have any EEPROM rountines built into it however, but the driver·say it does. I just never got arround to that.
Anyway, the I2C parts of the driver allow for transmiting and receiving I2C data, making start and stop conditions, aknowledging and not aknowledging, and clock·holding...etc.
Its pretty much everything you woyuld need.·Just call the·asm functions in the main loop to make yourself a driver for any I2C device that run at high speed in the background.
Also·the driver updates at 4 times the clock speed (that being·100 khz) and the driver can be modifed by chaning·to run at 400 khz by modifying the·initialization function.
And, the RTC part is kinda flaky. I don't know if·theres is a problem in the code or· in my own setup. So don't depend on it. Only trust the I2C·functions.
Beyond that, ask if you have any questions...
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
I spent some time working on a asm I2C driver for my propeller project. But after some redesigning of the project I have decided to drop it from my plans.
So... to put the code to good use I'll be posting it on the object exchange, the driver comes with some rountines to make a RTC (DS1307)·work. It does not have any EEPROM rountines built into it however, but the driver·say it does. I just never got arround to that.
Anyway, the I2C parts of the driver allow for transmiting and receiving I2C data, making start and stop conditions, aknowledging and not aknowledging, and clock·holding...etc.
Its pretty much everything you woyuld need.·Just call the·asm functions in the main loop to make yourself a driver for any I2C device that run at high speed in the background.
Also·the driver updates at 4 times the clock speed (that being·100 khz) and the driver can be modifed by chaning·to run at 400 khz by modifying the·initialization function.
And, the RTC part is kinda flaky. I don't know if·theres is a problem in the code or· in my own setup. So don't depend on it. Only trust the I2C·functions.
Beyond that, ask if you have any questions...
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
spin
53K
Comments
i have just tested your I2C driver with a DS1338, it seems to work fine. One question:
When do you write /red to the clock, i didn't understand your assembler code. What is triggering an acces to the I2C slave? a $FF to
in the RTCSet array? Or is the driver writing and reading permanently ?
Regards
Markus
The code block on the top checks to see if it needs to·setup the RTC. And the code part on the bottom does that. If it doesn't need to·setup the clock that part is skipped.
The driver reads and writes the NVRAM continuosly however. The idea behind that was that the driver would read in the values at startup and then rewrite them continuosly until shutdown. Thus any changes in the values·on the propeller chip would be instantly updated on the clock.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
thanks for your lst explanation.
The driver is running quite wll with my RTC.
Now i try just to expand your driver for a 2nd I2C device (its an Atmel as slave, measuring thermocouples)
Therefore i am studying your code in more details, an i am just wondering of the fuction of the
movs RAMUpdate , #7
is this way of changing a jump/call address ??
The user manual says something about self modifying code,
but i am to stupid to understand this.
Any hints ???
Regards
Markus
Basically, the driver loads all 64 registers from the RTC when it starts and then uses that command to make it only reload the first 7 from then on.
So...
->Read registers 0 - 63.
loop:
->Write registers 7 - 63.
->Read registers 0 - 6.
->GOTO loop
And that's essentially what that does. Using the principles of code reuse however.
I'm not changing the jmp/call address but just the immediant value in the asm instruction that code modifies.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Post Edited (Kye) : 5/22/2009 7:02:23 PM GMT
Very interesting driver. I'll have to modify it a bit to better suit my needs but this is a super head start. Thanks !!!
I wish this DS1307 had a seconds counter, just seconds since Jan 1st 1970
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
edit - just checked the datasheet, register 00 is seconds 0-59
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
I just want a seconds counter from 0 to 2^32-1. No days, no hours, no months, it does not have that :-(
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,