Shop OBEX P1 Docs P2 Docs Learn Events
I2C comment — Parallax Forums

I2C comment

KiwiKiwi Posts: 85
edited 2006-02-09 12:15 in General Discussion
I have written a simple I2C communcation routine.

Can somebody gave any comment concerning the subroutines

to use the current read model, beware that it writes to $00 and read from $01, like the specs of the 24LC01 said

Kurt

Comments

  • BeanBean Posts: 8,129
    edited 2006-02-07 15:24
    Kiwi,
    With I2C you should never pull the SDA or SCL lines high with the SX.
    That is the job of the pull-up resistor.
    The SX code should only pull the lines low or allow them to float (input).
    Look at the code generated by the SX/B I2C commands.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-02-07 16:35
    To distill what Bean is saying, when operating an open collector bus (which I2C is), instead of changing the data in the register, you instead change the pin direction from input to output and vice versa. When you set up the pin, you write a 0 to the bit(s) and you never change it(them) again. When you want the output to be 1, set the pin's direction to input. When you want the output to be 0, you set the pin's direction to output. The key is allowing the external pullup resistor to supply the 1 value.

    Its handy that the SX's pin direction definition is identical to what the data on the bus is, a 1 in the pin direction is a 1 on the bus, and a 0 in the pin direction is a 0 on the bus.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 2/7/2006 4:40:27 PM GMT
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2006-02-07 22:24
    As an exception to this rule, you may "hard drive" the SCL line from an I/O pin always configured as output, writing low and high level to SCL when the SX device doing this is the only master on the bus, and when no other device on the bus makes use of clock-stretching.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • KiwiKiwi Posts: 85
    edited 2006-02-08 14:51
    can you explain in more detail what the below text mean??

    "
    To distill what Bean is saying, when operating an open collector bus (which I2C is), instead of changing the data in the register, you instead change the pin direction from input to output and vice versa. When you set up the pin, you write a 0 to the bit(s) and you never change it(them) again. When you want the output to be 1, set the pin's direction to input. When you want the output to be 0, you set the pin's direction to output. The key is allowing the external pullup resistor to supply the 1 value.

    Its handy that the SX's pin direction definition is identical to what the data on the bus is, a 1 in the pin direction is a 1 on the bus, and a 0 in the pin direction is a 0 on the bus."


    Kurt
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-02-08 15:18
    There are two different types of busses, the first is active driven, where a chip supplies the high voltage and low voltage. The second is open collector, in this system the voltage isnt supplied by any one chip but by a resistor tied between Vdd and the line. Any chip communicating on the line either leaves it alone (hi impedance) or sinks the line thereby pulling it down to gnd. These two states are what causes the line to be either high or low. The reason for open collector lines is when there is the possibility of more than one chip trying to use the same bus, if it were an actively driven bus line, and one chip is driving it high at the same time another chip is driving it low, this creates a short circuit (low impedance path between Vdd and Gnd). Since this short is occuring internally inside two chips, one or both of the chips will burn out, something you definitely dont want to do.

    This explains the reason for using open collector busses, do you need more detail on how its implemented in an SX program as well?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 2/8/2006 3:39:03 PM GMT
  • KiwiKiwi Posts: 85
    edited 2006-02-09 07:23
    so what i needed to do is, where i wrote "setb sda","setb scl" in the routine i2cstart and i2cstop, i have to replaced the directions of these pin into Input (see file, i tested and works fine)??

    kurt
  • KiwiKiwi Posts: 85
    edited 2006-02-09 12:15
    oke, i figured out,

    to create logic 0,
    mov rc,#$00 put zero in rc register
    mode $0F
    mov !rc,#$00 make rc as output, with the value of 1° line

    to create a logic 1,
    mode $0F
    mov !rc,#$FF

    so i have to replaced all my setb and clrb with the above line according of what i need

    correct??

    can i use movB for switching bewteen Inputs and outputs?


    ps:the examples are always welcome
Sign In or Register to comment.