Shop OBEX P1 Docs P2 Docs Learn Events
How does this code work? — Parallax Forums

How does this code work?

kenmackenmac Posts: 96
edited 2010-01-10 06:40 in Propeller 1
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.

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

  • KyeKye Posts: 2,200
    edited 2010-01-10 04:07
    The outa register is always zero when a cog is started. So as long as that zeroed state is not changed the dira effectively sets the pin to high impedence mode and then to output low mode.

    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,
  • kenmackenmac Posts: 96
    edited 2010-01-10 04:31
    Thanks Kye.
    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
  • SamMishalSamMishal Posts: 468
    edited 2010-01-10 05:50
    kenmac said...
    Thanks Kye.
    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.
    What drives the speed of an I2C communication is the Clocking speed on the SCLK line. As long as the
    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
  • KyeKye Posts: 2,200
    edited 2010-01-10 06:40
    Spin is so slow when executing that type of code that no delay is neccessay. You hit only about 33KHZ tops at 80MHZ.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.