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.

I2C slave in a TI-RTOS application

Other Parts Discussed in Thread: TM4C123GH6PM

Hi

My config: TM4C123GH6PM on TivaC Series TM4C123G Launchpad, TivaWare C Series-2.1.1.71, TI-RTOS TivaC 2.14.00.10

Code Composer Studio Version: 6.0.1.00040 

I have to initialize an I2C Slave on a TI-RTOS application, but TI-RTOS does not support I2C Slave at this time. This means I have to write the code for this application by myself. The initialization I've adopted from the exaple at the following link.

https://e2e.ti.com/support/embedded/tirtos/f/355/t/371621

My revised initialization

    /* I2C3 Init */
    /*
     * NOTE: TI-RTOS examples configure pins PD0 & PD1 for SSI3 or I2C3.  Thus,
     * a conflict occurs when the I2C & SPI drivers are used simultaneously in
     * an application.  Modify the pin mux settings in this file and resolve the
     * conflict before running your the application.
     */
    /* Enable the peripheral */

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);

    // Configure the pin muxing for I2C3 functions on port D0 and D1.
    GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    GPIOPinConfigure(GPIO_PD1_I2C3SDA);

    // Select the I2C function for these pins.  This function will also
    // configure the GPIO pins pins for I2C operation, setting them to
    // open-drain operation with weak pull-ups.
    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
    GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
    GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_STRENGTH_8MA_SC,
    				GPIO_DIR_MODE_HW | GPIO_PIN_TYPE_OD);

    // Configure and turn on the I2C0 slave interrupt. The I2CSlaveIntEnableEx()
    // gives you the ability to only enable specific interrupts. For this case
    I2CSlaveIntEnableEx(I2C3_BASE, I2C_SLAVE_INT_DATA);
    // Enable the I2C3 slave module.
    I2CSlaveEnable(I2C3_BASE);
    // Set the slave address to SLAVE_ADDRESS.
    I2CSlaveInit(I2C3_BASE, 0b1010100);

     //These GPIOs are connected to PD0 and PD1 and need to be brought into a
     //GPIO input state so they don't interfere with I2C communications.

    GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
    GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_7);


    I2C_init();

Now i have no idea how to mange the slave in the TI-RTOS with the functons from \tirtos_tivac_2_14_00_10\products\TivaWare_C_Series-2.1.1.71b\driverlib\i2c.h

Can anyone help me?

Thanks a lot

Manuel

  • Hi Manuel,

    In general, when using TivaWare library APIs with TI-RTOS we suggest that the interrupts must be registered using the Hwi module. Also. since the library APIs are not re-entrant, the application should handle the re-entrancy conditions.

    Hope this helps.

    Vikram
  • #define TIVA_SLAVE_ADDRESS 	0x30
    #define SLAVE_BASE 		I2C0_BASE  
    
    // Configure and turn on the I2C0 slave interrupt. The I2CSlaveIntEnableEx()
        // gives you the ability to only enable specific interrupts. For this case
    	I2CSlaveIntEnableEx(SLAVE_BASE,I2C_SLAVE_INT_START);
    	I2CSlaveIntEnableEx(SLAVE_BASE,I2C_SLAVE_INT_STOP);
    	I2CSlaveIntEnableEx(SLAVE_BASE, I2C_SLAVE_INT_DATA);
        // Enable the I2C0 slave module.
        I2CSlaveEnable(SLAVE_BASE);
        // Set the slave address to SLAVE_ADDRESS.
        I2CSlaveInit(SLAVE_BASE, TIVA_SLAVE_ADDRESS);
    
        I2C_init();
    
    
    Void hwiFxnI2C0SlaveIntHandler (UArg arg0, UArg arg1)
    {
    	Interrupt_Status=I2CSlaveIntStatusEx(SLAVE_BASE, true); // Masked Interrupt Register auslesen
    	Slave_Status=I2CSlaveStatus(SLAVE_BASE); // Statusregister auslesen
    	if(Slave_Status!=2) // Transmit bit nicht gesetzt
    	{
    		switch(Interrupt_Status)
    		{
    			case 3:
    			{
    				Slave_Data[Count]=I2CSlaveDataGet(SLAVE_BASE); // Empfangene Daten abspeichern
    				Count++;
    				I2CSlaveIntClearEx(SLAVE_BASE, I2C_SLAVE_INT_DATA); // Dateninterrupt zurücksetzen
    				break;
    			}
    			case 6:
    			{
    				Value_of_Bytes=Count; // Anzahl Bytes abspeichern
    				Count=0;
    				I2CSlaveIntClearEx(SLAVE_BASE, I2C_SLAVE_INT_STOP); // Stop Interrrupt zurücksetzen
    				I2CSlaveIntClearEx(SLAVE_BASE, I2C_SLAVE_INT_START); // Start Interrupt zurücksetzen
    				break;
    			}
    		}
    	}
    	else
    	{
    		I2CSlaveDataPut(SLAVE_BASE, Slave_Data[Count]); // Daten zurücksenden
    		Count++;
    		I2CSlaveIntClearEx(SLAVE_BASE, I2C_SLAVE_INT_DATA); // Dateninterrupt löschen
    	}
    }
    

    So this is my working initialisation and HWI. The Comment is sometimes in german - sorry for that ;)
    I hope this will help someone else in another future application.