AnsweredAssumed Answered

KDS I2C SLAVE varible lenght

Question asked by Carl Norman on Apr 19, 2018
Latest reply on Jun 5, 2018 by Hui_Ma

Hi,

 

I am using a KL03 configured as I2C slave using the supplied driver example which works just fine. However, the dataSize is "fixed" and there is no example or explanation on how to change this dynamically without reading and understand the details of the driver. Basically I want to make the first byte of actual data the lenght that be transmitted or received.

 

Here is my callback code (which is pretty much identical to the example)

 

i2c_slave_handle_t g_s_handle;

static void i2c_slave_callback(I2C_Type *base, i2c_slave_transfer_t *xfer, void *userData)
{
switch(xfer->event)
{
case kI2C_SlaveTransmitEvent:
I2C_TXEvent = TRUE;
xfer->data = EWD_Packet;
xfer->dataSize = EWD_PacketSize;
break;

case kI2C_SlaveReceiveEvent:
I2C_RXEvent = TRUE;
xfer->data = EWD_Packet;
xfer->dataSize = EWD_PacketSize;
break;

case kI2C_SlaveCompletionEvent:
I2C_EventComplete = TRUE;
break;

default:
break;
}
}

 

I would have thought from a slave perspective it would just take data in until the master sends its stop for both TX / RX? Is that an option? If not can i read the first byte that arrives and decide from there how much data I want to receive without breaking the I2C communication?

Outcomes