Shop OBEX P1 Docs P2 Docs Learn Events
PropBASIC I2C. What is the default speed? — Parallax Forums

PropBASIC I2C. What is the default speed?

All I see is multipliers but no base.

Comments

  • pmrobertpmrobert Posts: 673
    edited 2016-05-14 13:44
    The default speed value is 1.0. I seem to recall that it's a divider not a multiplier, can take floating point values and is equal to 1 = 5 usec, 2 = 2.5 usec, etc. I just took a look at the Pascal compiler source and I think the above is correct. If you have the source, the relevant items are found in global.pas (line 2342 or so, "g_dI2CSpeed:=1.0" sets the default) and in i2c.pas, (search for "g_dI2CSpeed", it's referenced in the 5 I2C instructions, (start, stop, read, write and speed) and you can see how the waitcnt in the PASM output is derived).

    Basically, where g_lFreq is clkfreq and the g_I2CSpeed is the speed variable the algorithm seems to be:
        dDelay:=g_lFreq Div 200000;
        dDelay:=dDelay / g_dI2CSpeed;
        lDelay:=Trunc(dDelay);
        If lDelay < 20 Then lDelay:=20;
    

    Edit: The default speed seems to be 200kHz.
  • Cool....many thanks!
  • Another memory re PropBasic/I2C popped into my head. I've optimized the speed by an empirical method; increase the speed var by 0.5 until your I2C ops fail then back off 0.5. That has worked reliably for me, of course, YMMV! Also, the compiler limits the waitcnt value it generates to no less than 20. Unless you're running a super slow clock the transactions will fail far before that hard limit is reached.
  • I'd like to hit the 400KHz mark if possible......Thanks again!
  • Related to I2C speed... I have been sharing the EEPROM I2C buss with other devices and ran into a problem with multi-mode (SPI, I2C, serial) displays: many of them are low speed (100kHz) devices and do not like the speed used by the Propeller when writing to or booting from the EEPROM.
  • MicksterMickster Posts: 2,693
    edited 2016-05-15 00:26
    Sorry Jon, I read that like 6 times but still not sure.....are you recommending not sharing the bus with the EEPROM? I do have other spare pins.


    Edit: BTW, I don't intend to be writing to the EEPROM and my I2C devices are other microcontrollers that won't be communicating until well after boot-up.
  • You can share the EEPROM I2C buss -- with caution. What you must do before adding a device is ensure that it can operate at the speed the Propeller uses when booting from or programming the EEPROM. I measured this at about 270kHz (remember, it's in RC mode when booting so it can vary). As long as your device can handle a clock that fast, you're okay.

    Case in point: a customer in the escape room business wanted to add an I2C LCD and I2C 7-segment display to an HC-8+ controller that extends the EE I2C buss with a buffer. It all worked fine until I went to program the EEPROM, then I got a fail message. When I checked the device specs they were only capable of 100kHz I2C clock speed. My guess is that the fast clock was causing them to output errant 0s while the EEPROM was being written to and verified, causing the failure. The same thing happened on boot up.

    These devices could run I2C, SPI, and serial, hence were not as fast as a native I2C device. You will have to test your other microcontrollers (my devices had Arm variants in them). I tested some LCDs with standard I2C chips (PCF8474x and MCP23008) and neither bothered the programming or boot sequence.
  • Hmmm, I'd forgotten about extenders/buffers. Must investigate.

    Lying in bed with my lil lady, she got curious and Googled you...I think she fancies you :swear: :D
Sign In or Register to comment.