Rei Vilo 695 Posted March 7, 2014 Share Posted March 7, 2014 See post at http://forum.43oh.com/topic/5130-help-—-how-to-implement-clock-stretching-for-i²c-on-tiva-c/?p=45240 Edit — Solved with pull request at http://github.com/energia/Energia/pull/375 Quote Link to post Share on other sites
Rei Vilo 695 Posted April 21, 2014 Author Share Posted April 21, 2014 Here's the solution that I've tested on port I²C (3) of the Stellaris LM4F120 and Tiva C TM4C123 LaunchPads. Libraries to include with #include "Wire.h" #include "driverlib/i2c.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" This routine initialise the SCL pin. Not sure it is really useful. void stretchInit() { SysCtlPeripheralEnable(I2C_SCL3_PERIPH); } This routine configures the SCL line as a standard output and sets it LOW. Not sure about the 4mA parameter. void stretchPause() { // Standard output GPIOPadConfigSet(I2C_SCL3_BASE, I2C_SCL3_PIN, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); GPIODirModeSet(I2C_SCL3_BASE, I2C_SCL3_PIN, GPIO_DIR_MODE_OUT); // Set LOW GPIOPinWrite(I2C_SCL3_BASE, I2C_SCL3_PIN, 0); } This routine configures the SCL line back to normal. I tried another option but it didn't work. void stretchResume() { // Reconfigure for I2C ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL); ROM_GPIOPinTypeI2CSCL(I2C_SCL3_BASE, I2C_SCL3_PIN); // Doesn't work // HIGH for floating? // GPIOPinWrite(I2C_SCL3_BASE, I2C_SCL3_PIN, I2C_SCL3_PIN); // Open drain // GPIOPadConfigSet(I2C_SCL3_BASE, I2C_SCL3_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD); // GPIODirModeSet(I2C_SCL3_BASE, I2C_SCL3_PIN, GPIO_DIR_MODE_HW); } Typical usage requires adding stretchInit(); in setup() including stretchPause(); on the first line of void ReceiveEvent(int howMany) as the I²C sequence is buffered placing stretchResume(); on the last line of the routine in charge of executing orders from I²C. Questions: How to make it universal for the 4 I²C ports available in the LM4F and TM4C MCUs? How to integrate the routines directly into the Wire.h library? How to check the whole process is safe —which values for pull-up resistors, which parameter for mA, no shorts, no damage for the MCU? Thanks! Quote Link to post Share on other sites
Rei Vilo 695 Posted April 21, 2014 Author Share Posted April 21, 2014 I've integrated the solution into the Wire library and prepared a pull-request. See ticket at https://github.com/energia/Energia/issues/336 pull request at https://github.com/energia/Energia/pull/375 I've tested it on LM4F120- and TM4C123-based LaunchPads Please proceed with other tests and commit! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.