Shop OBEX P1 Docs P2 Docs Learn Events
iic question — Parallax Forums

iic question

tholbertontholberton Posts: 41
edited 2012-06-03 19:23 in General Discussion
I'm writing an assembly routine for iic, and I realize that the other device is suppose to send an acknowledgement bit.
I'm just not really sure how the pin on the prop is suppose to sense that acknowledge bit, because the pin gets set to
an output right beforehand in order to set the voltage high on the other device. Can anyone explain this to me?

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-06-02 17:30
    You shouldn't need to set the pin high. The I2C bus should have pull-up resistors on both lines (some Prop boards only have them on the data line).

    To send a low signal (or clock) the Prop pin is set to an output (it always stays low). For a high bit (or clock) the pin is switched to an input. The pull-up resistors should bring the line high while the pin is in an input state. In the input state you should be able to read the incoming ack.

    A pull-up doesn't drive a line high as fast as if the Prop were setting it high. I think it's possible this delay can contribute to making I2C communication slower than other alternatives (though I think the addressing required in I2C is the main speed killer).

    Not all the I2C objects obey this rule (of using an open drain) and drive the pins high (which is against the rules) so you'll need to check the object you're using to make sure it's not driving pins high.
  • tholbertontholberton Posts: 41
    edited 2012-06-02 17:59
    I'm not setting it high, just as an output. I plan on using the pull-up resistors as well. I'm just not understanding the circuitry that well.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-06-02 18:12
    I'm not setting it high, just as an output.

    Then I don't understand what you mean here:
    tholberton wrote: »
    because the pin gets set to
    an output right beforehand in order to set the voltage high on the other device.
  • tholbertontholberton Posts: 41
    edited 2012-06-02 18:17
    yea, I guess I got that backwards. so it's suppose to be set as an input to set the line high? that's so strange. so how does the acknowledge bit get sent from the other device?
  • davejamesdavejames Posts: 4,047
    edited 2012-06-02 19:38
    tholberton wrote: »
    yea, I guess I got that backwards. so it's suppose to be set as an input to set the line high? that's so strange. so how does the acknowledge bit get sent from the other device?

    An I2C "transaction" consists of 9 clock cycles of which 8 cycles contain data sent to the 'slave' device. The 9th cycle is for the acknowledge from the slave device. Key item: the acknowledge is a LOW, not a high.

    So during that 9th cycle, the Prop pin used as the I2C SDA must be set as input and the state tested to see if the slave pulled the input low - indicating that it received/undestood the previous 8 bits of data. If the slave did not understand, then it just allows the SDA line to be pulled high by the pull-up resistors.

    Did that make sense?

    Go here for all you would ever want to know about the I2C bus:

    http://www.i2c-bus.org/
  • tholbertontholberton Posts: 41
    edited 2012-06-02 19:44
    okay, i'm gonna guess the slave device makes its bin an output to drive the line low. Thanks Duane, you've helped me a lot already! haha.
    I'm still trying find an explanation of how that works from a circuit perspective, but at least I can keep writing code now.
  • tholbertontholberton Posts: 41
    edited 2012-06-02 19:46
    oh thanks davejames! you just hit gold with that link, thanks a bunch!
  • davejamesdavejames Posts: 4,047
    edited 2012-06-03 19:23
    tholberton wrote: »
    oh thanks davejames! you just hit gold with that link, thanks a bunch!

    ..welcome - happy to help!

    :thumb:
Sign In or Register to comment.