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_MODE_CALLBACK

Other Parts Discussed in Thread: TM4C123GH6PM, EK-TM4C123GXL

We have a SE97b chip on our board, and I'm trying to read the eeprom using I2C_MODE_CALLBACK, but the callback is never called.

Code:

uint8_t         g_eepromTxBuffer[1];
uint8_t         g_eepromRxBuffer[256];
I2C_Handle      g_i2c;
I2C_Params      g_i2cParams;
I2C_Transaction g_i2cTransaction;

/*********************************************************************************************************************//** * initialize the eeprom reader variables *************************************************************************************************************************/ void initEL1042EEPROM() { /// Create I2C for usage I2C_Params_init(&g_i2cParams); g_i2cParams.bitRate = I2C_100kHz; g_i2cParams.transferMode = I2C_MODE_CALLBACK; g_i2cParams.transferCallbackFxn = EEPROMCallbackFxn; /// Point to the T ambient register and read its 2 bytes g_eepromTxBuffer[0] = 0x00; g_i2cTransaction.slaveAddress = SE97B_ADDR_EEPROM; g_i2cTransaction.writeBuf = g_eepromTxBuffer; g_i2cTransaction.writeCount = 1; g_i2cTransaction.readBuf = g_eepromRxBuffer; g_i2cTransaction.readCount = 256; /// set the lens to offline lens1.conn = LENS_OFFLINE; }

/*********************************************************************************************************************//**
 * read the lens eeprom
 *************************************************************************************************************************/
void ReadEL1042EEPROM()
{
	g_i2c = I2C_open(Board_I2C_TMP, &g_i2cParams);
	if (g_i2c == NULL) {
		lens1.conn = LENS_I2C_INIT_ERROR;
#ifdef DEBUG
		System_abort("Error Initializing I2C\n");
#else
		return;
#endif
	}
	else {
		if (I2C_transfer(g_i2c, &g_i2cTransaction)) {
			/// we got the EEPROM, lens is connected
			lens1.conn = LENS_ONLINE;
#ifdef DEBUG
			System_printf("eeprom read\n");
			System_flush();
#endif
		}
		else {
			/// there is no lens connected
			lens1.conn = LENS_OFFLINE;
#ifdef DEBUG
			System_printf("I2C Bus fault\n");
			System_flush();
#endif
		}
		/// Deinitialized I2C
		I2C_close(g_i2c);
	}
}

/*********************************************************************************************************************//**
 * callback
 *************************************************************************************************************************/
void EEPROMCallbackFxn(I2C_Handle handle, I2C_Transaction *transaction, bool result)
{
	initStruct();
}

and on my .cfg file I've declared:

hwi0Params.instance.name = "i2cHwi";
Program.global.i2cHwi = Hwi.create(52, "&EEPROMCallbackFxn", hwi0Params);

initEL1042EEPROM() is called at the beginning of the applications,

and ReadEL1042EEPROM() is called from a Task.

if someone could point me to the right direction I would appreciate.

Thanks

  • Eduardo,

    What device are you using?

    The I2C callback function is not to be installed as a Hwi.

    Unless you are using a MSP430, the I2C driver will install its own Hwi (in I2C_open) which invokes your callback function after a I2C_transfer has finished.

    (On MSP430's, you need to create this Hwi in the .cfg file. See the TI-RTOS User guide.)

  • Thanks for the reply Tom,

    I'm using a board developed in house using the Tiva TM4C123GH6PM.

    since I keep the code compatible with the Tiva c board EK-TM4C123GXL, I've just tried my code on it and the I2C_MODE_CALLBACK does work.

    I don't know what the problem could be, if you have an idea please let me know, otherwise I'll keep working on I2C_MODE_BLOCKING until I find the problem.

    thanks.

  • Eduardo,

    in I2C_MODE_CALLBACK, the I2C_transfer "kicks" off the I2C transaction and it will always return false. The callback function will let you know when it finished the I2C transaction.

    This allows you to run some other code between calling I2C_transfer and getting the callback. In blocking mode, you are guaranteed that the transaction has actually finished when you return from I2C_transfer().