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.

Stellaris launchpad i2c slave

Hi!

I've written a code to my Stellaris launchpad to use 2 I2C module, I2C0 and I2C1. I2C0 is the master, and I2C1 is the slave. The problem is that the I2C1 doesn't get the data that I send from I2C0. Then, I connected the I2C0 with Arduino, to determine wether the I2C0 is working properly or not. On Arduino I could read the data.

Here is the code:

0511.main.c

Sorry for my english :) 

Thanks in advance!

  • Hi,

    here's the code snipped for initializing I2C0 as a master (400kHz; Stellarisware in ROM):


        //
        // I2C0 is used with PortB[3:2].  The actual port and
        // pins used may be different on your part, consult the data sheet for
        // more information.  GPIO port B needs to be enabled so these pins can
        // be used.
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

        //
        // Select the I2C function for these pins.  This function will also
        // configure the GPIO pins for I2C operation, setting them to
        // open-drain operation with weak pull-ups.  Consult the data sheet
        // to see which functions are allocated per pin.
        //
        GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); // special I2CSCL treatment for M4F devices
        ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

        //
        // Configure the pin muxing for I2C0 functions on port B2 and B3.
        // This step is not necessary if your part does not support pin muxing.
        //
        ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
        ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    //
    // The I2C0 peripheral must be enabled before use.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    //
    // Enable and initialize the I2C0 master module.
    //
    ROM_I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), true);

    Don't do this:

    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);

    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);

    Rgds
    aBUGSworstnightmare 

  • Thanks, but as I wrote I want to use the second I2C module (I2C1) as a slave with interrupts enabled, but I can't get it to work.

  • From the main you posted, you have I2CSlaveEnable(I2C0_SLAVE_BASE) and I2CSlaveInit(I2C0_SLAVE_BASE, 0x3B). You need to switch the I2C0_SLAVE_BASE to I2C1_SLAVE_BASE. Hope this helps!

  • I see, accidentaly I uploaded the wrong code. I tried that you wrote but nothing happened. I think I configured the gpio in a wrong way. I2C0 can work in slave mode with that code, but I2C1 don't. I hope you understand my problem, but I'll upload my last code I used to configure the I2C. Thanks

  • Where you able to fix the code? If you were able, could I see the code? I am having trouble with my code. I am not able to get I2C1 to work as a master properly.