Shop OBEX P1 Docs P2 Docs Learn Events
Do I2CIN and I2COUT support clock stretching? — Parallax Forums

Do I2CIN and I2COUT support clock stretching?

ZootZoot Posts: 2,227
edited 2008-08-13 18:08 in BASIC Stamp
My guess right now is that they DO.

But I can't find anything in the documentation one way or the other. This came up while porting some code from a BS2p40 to an SX.

Anyone from Parallax have a definitive answer?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-13 15:17
    If you look at the schematic for the BS2p24, say, you will notice that SCL is not pulled up to Vdd. This implies definitively that the PBASIC I2C instructions do not support clock stretching.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 8/13/2008 4:40:32 PM GMT
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-08-13 16:09
    The I2C commands does support clock stretching. I believe that was added in a very early revision of the BS2p, so it should be available in all the supported 'p devices. I have used it successfully, for example, with the MAX1238 ADC, which needs clock stretching to hold off the communication until a conversion is finished.

    Phil, it is true that scl is driven without a pullup for the interpreter eeprom, but that does not apply to the regular pins. Both sda and scl require pullups.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-13 16:37
    Tracy,

    You're right, of course! The I2C commands have nothing to do with the onboard EEPROM. (That'll teach me post on the forums before I've had my morning coffee!) D'oh! blush.gif

    -Phil
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-08-13 16:44
    Phil,

    Ahh, the coffee! Maybe you were cog-itating too hard and late last night on the phsx question (very interesting). I'm through my own cup of joe now, perking up.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ZootZoot Posts: 2,227
    edited 2008-08-13 16:56
    Thanks gents. This answers a big question. My feeling is that it DOES because:

    - I've used I2CIN I2COUT with an MD22 motor controller. That board is based on a PIC187Fx which clock stretches (under certain conditions)

    - I built a simple I2C_SEND, I2C_RECV app in SX/B which failed utterly.

    - when I used the beta SX/B, it worked. The only difference? The next release of SX/B supports clock stretching.

    - lastly, it would seem that given the incredible ease of I2C on the Stamps that have these commands, if clock stretching were NOT supported, there would be folks having a whole lot more problems vis a vis Stamps/I2C

    I spent two evenings trying to figure out why I couldn't read a register from the dang thing.... ugh.

    Somebody said...
    The I2C commands have nothing to do with the onboard EEPROM

    PhiPi -- while the commands and the on-board eeprom don't answer any questions (that eeprom does not clock stretch), I actually think that the I2C commands are a kind of primitive on these flavor Stamps. I say this because of all the commands, I2CIN and I2COUT take up almost no code space (in fact, wrapping I2C commands in a subroutine often *increases* code space). I am guessing that since the Stamp itself spends a huge chunk of time fetching instructions via I2C from the token eeprom, that these are very basic and condensed to the whole shebang. Just a thought.

    If anyone from Parallax is reading this -- a note about clock-stretching in the docs would be very helpful (if it's there already, I couldn't find it).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-08-13 17:50
    Zoot, refer to the document on the Parallax web site,

    BASIC Stamp® 2p Module Firmware Revision Details

    There have been several tweaks made to the I2C command through the revisions up to the present v1.7. The IDE no longer supports versions earlier than 1.3. Clock stretching is not mentioned in the revision doc, which only goes back to v1.3, so it may have been a tweak in an earlier rev. I agree that is is a good thing to know, but clock stretching is not that common.

    Another tidbit that is good to know is that the I2C commands do time out if they do not receive a response, so you don't have to worry that a program will hang on an I2c command if the device is defective or disconnected.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ZootZoot Posts: 2,227
    edited 2008-08-13 18:08
    Thanks.
    Somebody said...
    Another tidbit that is good to know is that the I2C commands do time out if they do not receive a response, so you don't have to worry that a program will hang on an I2c command if the device is defective or disconnected.

    I knew this from tests and experience (on the Stamps), but not for a fact. In my apps, if knowing if the device is online is important, I usually read a firmware register, or other known data at a register and compare it, if it's bad then the host knows the I2C devices is not responding (for whatever reason), e.g.

    FW CON $99 ' or whatever
    ioByte = 0
    online = 0
    I2CIN SDA, FirmRegister, [noparse][[/noparse] iobyte ]
    IF iobyte = FW THEN
    online = 1
    ENDIF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.