This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LX4F and I2C1 initialization

Hi, I'm trying to setup PA6 and 7 as I2C1 and have a very hard time :(

here is a code that I'm using (an example from stellarisware - slave_receive_int.c, but adopted for I2C1):

[code]
// Setup clock and interrupts
ROM_FPUEnable();
ROM_FPULazyStackingEnable();

ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

// I2C
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);

// Configure peripherals that are being used
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Display, I2C


ROM_GPIOPinConfigure(GPIO_PA6_I2C1SCL);
ROM_GPIOPinConfigure(GPIO_PA7_I2C1SDA);
ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);

ROM_I2CMasterInitExpClk(I2C1_MASTER_BASE, SysCtlClockGet(), false);

ROM_I2CMasterIntEnable(I2C1_MASTER_BASE);
ROM_I2CSlaveEnable(I2C1_SLAVE_BASE);
ROM_I2CSlaveInit(I2C1_SLAVE_BASE, 0x11);
ROM_I2CSlaveIntEnable(I2C1_SLAVE_BASE);

ROM_IntEnable(INT_I2C1);
[/code]

I have 2 pull-ups and scope on PA6 and 7. 

And right after "ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);" line of code executes I2C-Clock goes low, and remains low. 

Any suggestions?

  • Can you tell me some background information:

    Which LM4Fxxx part are you using?

    Are you working on an evaluation kit, or your own custom design?

    Lela

  • I'm trying the code on Both EKS-LM4F232 Eval Kit, and custom design board (based on LX4F120E). Trying I2C1 on both boards. 

    Thank you Lela!

  • Quickly - several items jump out:

            GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);   //   I2CSCL required for M4 parts

    SYSCTL_SYSDIV_1 and your use of SYSCTL_USE_PLL - - Just how fast do you think your MCU will then run?

    Would you not be better served by using an I2C in Master - rather than Slave mode?  (at least for preliminary check out)

    6 months or so past - I posted first known, complete set-up/config "working" code for basic M4 I2C operation.  Forum search should reveal...

  • cb1_mobile said:
    6 months or so past - I posted first known, complete set-up/config "working" code for basic SSI operation.  Forum search should reveal...

    ... and there's also a working example API in the Code Sharing Section ...

  • Thank you sir! 

    GPIOPinTypeI2CSCL did the trick. Point, about Divider and PLL, taken, I assume it wasn't really running at 200Mhz. I copied rest of the initialization from the driver I did for LM3 years ago, that's why it also inits Slave Mode. 

    Too bad that StellarisWare doesn't contain proper I2C init sample for M4 parts :/

  • My pleasure - my friend, and thank you.  You were almost there - and good for you re: PLL and likely divide by 4.  (for 50MHz opn.)

    At some point - vendor staff will address that, other issues - for now your best bet is to post here - and use the forum search function.  Much "breaking news" here - which cannot/has not yet made it into, "official release... "

    Final point - (for you/others) do note that ROM version of, "GPIOPinTypeI2CSCL" had not yet made it into "normal" ROM code (w/in MCU) - thus my quite deliberate use of Flash version - for that function.  (and MAP call would also work...)

  • If you really want to use the ROM functions, ROM_GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6) will do the same thing as GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6).

  • While counter intuitive - and w/the caveat that you confine this to Blizzard class & beyond - you appear correct.

    GPIO.C reveals only this difference: (below is encoded w/in GPIOPinTypeI2CSCL() - Ver 9453:)

     if(CLASS_IS_SANDSTORM || CLASS_IS_FURY || CLASS_IS_DUSTDEVIL ||
           CLASS_IS_TEMPEST || CLASS_IS_FIRESTORM)
        {
            GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
        }

    That code block does not appear w/in GPIOPinTypePWM().   Otherwise - code is line for line duplicative.

    As TI's Dave W. has herein noted - even a "single usage" of non-ROM function - causes the full addition of that code's base w/in Flash. 

    Your language can be strengthened via, "If you really want to exclusively use the ROM I2C functions..."

    Curious as to your motivation for this discovery - yours is the first such mention to my knowledge...  (as I spend some limited time here - other ARM/tech forums...)  Not too bad a, "first-time" post (really quite extraordinary!....)

    Update: unknown yet is whether the apparent "clash" between GPIOPinType() (as PWM - under your discovery) and GPIOPinConfigure() (as I2C) may someway/somehow "disrupt" any of the IDEs or any related Stellaris codings...