lpcware

I2C Events

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by rubensm on Sun Jan 11 08:47:57 MST 2015
Hello everybody,

Can anyone explain what does function i2c_iox_events do exactly? I want to edit this function in order to fit it according to my needs, but I don't understand the differences between I2C_EVENT_DONE, I2C_EVENT_SLAVE_RX and I2C_EVENT_SLAVE_TX. How do I have to handle these events to send or receive correctly my data as slave?

What I understand is when master resquests for data to the slave, I2C_EVENT_SLAVE_TX is active. But if I do this:
  case I2C_EVENT_SLAVE_TX:
  iox_data[0] = 0x49;//H
  iox_data[1] = 0x48;//i

  iox_xfer.txBuff = iox_data;// buffer[0];

  break;


Then, LPC11U68 only sends H. If I request for 2 bytes, what I get is HH.

The original function is:
/* Slave event handler for simulated EEPROM */
static void i2c_iox_events(I2C_ID_T id, I2C_EVENT_T event)
{
switch (event) {
case I2C_EVENT_DONE:
iox_xfer.rxBuff = &iox_data[1];
iox_xfer.rxSz = sizeof(iox_data);
iox_xfer.txBuff = (const uint8_t *) iox_data;
iox_xfer.txSz = sizeof(iox_data) + 1;
break;

case I2C_EVENT_SLAVE_RX:
iox_xfer.rxBuff = &iox_data[1];
iox_xfer.rxSz = sizeof(iox_data);
i2c_iox_update_regs(1);
break;

case I2C_EVENT_SLAVE_TX:
if (iox_xfer.txSz == 1) {
iox_xfer.txBuff = (const uint8_t *) iox_data[0];
iox_xfer.txSz = sizeof(iox_data) + 1;
}
break;
}
}


And this function is called by i2c_iox_events:
/*-------- IO Expansion slave device implementation ----------*/
/* Update IN/OUT port states to real devices */
void i2c_iox_update_regs(int ops)
{
if (ops & 1) {/* update out port */
Board_LED_Set(0, iox_data[1] & 1);
Board_LED_Set(1, iox_data[1] & 2);
Board_LED_Set(2, iox_data[1] & 4);
Board_LED_Set(3, iox_data[1] & 8);
}
}



Thank you very much for your help.

Rubén

Outcomes