Part Number: TM4C123GE6PM
Other Parts Discussed in Thread: SYSCONFIG
Tool/software: Code Composer Studio
Hello all,
I am looking for a proper way to make an I2C slave with my tiva, on the I2C3, with TI_RTOS.
I have found a lot of contradictory information about this, especially concerning the API to use.
As I already have some I2C configured in Master mode, as follow :
/*
* =============================== I2C ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(I2C_config, ".const:I2C_config")
#pragma DATA_SECTION(i2cTivaHWAttrs, ".const:i2cTivaHWAttrs")
#endif
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CTiva.h>
I2CTiva_Object i2cTivaObjects[EK_TM4C123GXL_I2CCOUNT];
const I2CTiva_HWAttrs i2cTivaHWAttrs[EK_TM4C123GXL_I2CCOUNT] =
{
{
.baseAddr = I2C1_BASE,
.intNum = INT_I2C1,
.intPriority = (~0)
},
{
.baseAddr = I2C2_BASE,
.intNum = INT_I2C2,
.intPriority = (~0)
},
};
const I2C_Config I2C_config[] =
{
{
.fxnTablePtr = &I2CTiva_fxnTable,
.object = &i2cTivaObjects[0],
.hwAttrs = &i2cTivaHWAttrs[0]
},
{
.fxnTablePtr = &I2CTiva_fxnTable,
.object = &i2cTivaObjects[1],
.hwAttrs = &i2cTivaHWAttrs[1]
},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C123GXL_initI2C ========
*/
void EK_TM4C123GXL_initI2C(void)
{
/* I2C1 Init */
/* Enable the peripheral */
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
/* Configure the appropriate pins to be I2C instead of GPIO. */
GPIOPinConfigure(GPIO_PA6_I2C1SCL);
GPIOPinConfigure(GPIO_PA7_I2C1SDA);
GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
/*
* 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.
*/
/*I2C2 Init*/
/* Enable the peripheral */
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);
/* Configure the appropriate pins to be I2C instead of GPIO. */
GPIOPinConfigure(GPIO_PE4_I2C2SCL);
GPIOPinConfigure(GPIO_PE5_I2C2SDA);
GPIOPinTypeI2CSCL(GPIO_PORTE_BASE, GPIO_PIN_4);
GPIOPinTypeI2C(GPIO_PORTE_BASE, GPIO_PIN_5);
/*I2C3 Init*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinConfigure(GPIO_PD0_I2C3SCL);
GPIOPinConfigure(GPIO_PD1_I2C3SDA);
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
/*
* 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);
/****/
// Enable and initialize the I2C0 master module. Use the system clock for
// the I2C0 module. The last parameter sets the I2C data transfer rate.
// If false the data rate is set to 100kbps and if true the data rate will
// be set to 400kbps.
I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false);
I2CMasterInitExpClk(I2C2_BASE, SysCtlClockGet(), false);
//clear I2C FIFOs
HWREG(I2C1_BASE + I2C_O_FIFOCTL) = 80008000;
HWREG(I2C2_BASE + I2C_O_FIFOCTL) = 80008000;
/****/
I2C_init();
}
An I use it like this :
I2C_Params_init(&DRI_astrI2CConfig[idx].I2cParams);
DRI_astrI2CConfig[idx].I2cParams.transferMode = I2C_MODE_BLOCKING;
DRI_astrI2CConfig[idx].I2cParams.transferCallbackFxn = NULL;
DRI_astrI2CConfig[idx].I2cParams.bitRate = I2C_100kHz;
DRI_astrI2CConfig[idx].I2cHandle = I2C_open(DRI_astrI2CConfig[idx].PeripheralNum, &DRI_astrI2CConfig[idx].I2cParams);
if (DRI_astrI2CConfig[idx].I2cHandle == NULL)
{
/* Error opening I2C */
System_printf("I2C was not opened");
System_flush();
}
I2C_transfer(handle, i2c);
I would like to add in a similar way my I2CSlave. So I have found this driver http://dev.ti.com/tirex/content/simplelink_msp432_sdk_1_30_00_40/docs/tidrivers/doxygen/html/_i2_c_slave_8h.html#a4adcea9698de83af86f5d9d4e4331977 That seemed to correspond to my needs, but I don't know if it is possible to use it in my case and how to install it.
So I look for an other solution, to use only the functions contained in driverlib/i2c.h, such as I2CSlaveInit, I2CSlaveDataGet., as in the examples contained in ti/TivaWare_C_Series../examples/peripherals/ i2c/ but I am not sure either it is the right way to do this.
Could anyone explain me the difference between the two methods, and which one I must use ?
Any example would be welcome!
Thank you,
Elisabeth