KDS I2C SLAVE varible lenght

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KDS I2C SLAVE varible lenght

1,293 Views
carlnormansuret
Contributor V

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?

Labels (1)
0 Kudos
5 Replies

1,021 Views
carlnormansuret
Contributor V

After spending a good 30 hours I worked out the FSL implementation has a bug in it. My solutions has a master with KL03 slave and 24C64 EEPROM. If the master talks to the EEPROM on another address first the FSL I2C slave driver ends up in some strange state where it will only respond to TX events from the master, and will NOT respond to the RX requests at all. All I had to do was make sure the master does a TX/RX to the KL03 first and there is no issue after that.

I did not and do not have time to track down what is wrong with the FSL driver but its definitely a problem...

0 Kudos

1,021 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Carl,

What's the MCUXpresso SDK software version you are using?

Please help to provide the detailed I2C driver info.

I will check with SDK software team for your comments.

best regards,

Mike

0 Kudos

1,021 Views
carlnormansuret
Contributor V

Copied from the fsl_i2C.h

/*! @brief I2C driver version 2.0.3. */

I am using KL03 in slave mode

There is NO issue with anything as long as the master talks to the KL03 first, but, if the master talks to my EEPROM 24C64 first in any way, then the KL03 locks up somewhere around the time kI2C_SlaveTransmitEvent happens. The address arrives, the bus stays low, and nothing happens.

void I2C_Slave_Config(void)
{
i2c_slave_config_t slaveConfig;
/*1.Set up i2c slave first*/
/*
* slaveConfig->addressingMode = kI2C_Address7bit;
* slaveConfig->enableGeneralCall = false;
* slaveConfig->enableWakeUp = false;
* slaveConfig->enableBaudRateCtl = false;
* slaveConfig->enableSlave = true;
*/
I2C_SlaveGetDefaultConfig(&slaveConfig);
slaveConfig.addressingMode = kI2C_Address7bit;
slaveConfig.slaveAddress = EWD_SLAVE_ADDR_7BIT;
slaveConfig.upperAddress = 0;

I2C_SlaveInit(EXAMPLE_I2C_SLAVE_BASEADDR, &slaveConfig, I2C_SLAVE_CLK_FREQ);

memset(&g_s_handle, 0, sizeof(g_s_handle));

I2C_SlaveTransferCreateHandle(EXAMPLE_I2C_SLAVE_BASEADDR, &g_s_handle, i2c_slave_callback, NULL);

I2C_SlaveTransferNonBlocking(EXAMPLE_I2C_SLAVE_BASEADDR, &g_s_handle, kI2C_SlaveCompletionEvent);

}

0 Kudos

1,021 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

Sorry for the later reply.

Currently, the MCUXpresso SDK for FRDM-KL03Z software version is V2.3.1.

pastedImage_1.png

The KL03 SDK software provides interrupt and polling modes I2C slave driver and demo project.

Please download the latest SDK software from here and check if there with the same issue.

Wish it helps.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,021 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

I think there need two round communication between I2C master and slave:

First round just let I2C slave knows how many bytes will tx/rx from I2C master;

The next round just to do actual communication (tx/rx known number bytes).

Thank you for the attention.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos