How does this code work?
kenmac
Posts: 96
Hi folks,
The following code is an extract from an i2c object used to transmit to a DS1307.
It does work, I just don't understand it.
Can someone please explain how the bit values are put onto the Clock & Data lines.
I see only DIRA's, which normally set the Input/Output modes.
kenmac
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Perth, Western Australia
Time Zone = GMT + 8
The following code is an extract from an i2c object used to transmit to a DS1307.
It does work, I just don't understand it.
Can someone please explain how the bit values are put onto the Clock & Data lines.
I see only DIRA's, which normally set the Input/Output modes.
PRI transmitPacket(value) value <<= 24 repeat 8 value <-= 1 dira[noparse][[/noparse]constant(((Data_Pin <# 31) #> 0))] := ((!value) & 1) dira[noparse][[/noparse]constant(((Clock_Pin <# 31) #> 0))]~ dira[noparse][[/noparse]constant(((Clock_Pin <# 31) #> 0))]~~ dira[noparse][[/noparse]constant(((Data_Pin <# 31) #> 0))]~ dira[noparse][[/noparse]constant(((Clock_Pin <# 31) #> 0))]~ dira[noparse][[/noparse]constant(((Clock_Pin <# 31) #> 0))]~~ dira[noparse][[/noparse]constant(((Data_Pin <# 31) #> 0))]~~
kenmac
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Perth, Western Australia
Time Zone = GMT + 8
Comments
The bus I2C lines are pulled high by resistors. Thus open drain communication is achieved in which every device on the bus only either pulls the bus line low from its regular high state or goes into high Z mode.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
There doesn't seem to be any timing code - the Tx would be fast.
Is there any chance that can be a problem with the DS1307?
I'm running the Clock at 40mHz and it works OK.
kenmac
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Perth, Western Australia
Time Zone = GMT + 8
data SDA line is set and settled and the clocking speed does not exceed the latching ability of the device
then it won't be a problem.
The speed of each instruction in SPIN is in the order of MicroSeconds when running at 80 MHz clock.
So there will be plenty of time between each high and low to be·well within the latching settling time of the Ds13077.
In PASM you might have to do a bit of a delay between the setting of the Clock line to·output and then back to input
since pasm will excecute instruction in the order of Nano Seconds and that might be too fast.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Samuel
www.RobotBASIC.com
Post Edited (SamMishal) : 1/10/2010 6:44:17 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,