Hello @kerryzhou thank you for your reply. i implement the following code:
#define EXAMPLE_I2C_MASTER_BASE (LPI2C3_BASE)
/* Select USB1 PLL (480 MHz) as master lpi2c clock source */
#define LPI2C_CLOCK_SOURCE_SELECT (0U)
/* Clock divider for master lpi2c clock source */
#define LPI2C_CLOCK_SOURCE_DIVIDER (5U)
/* Get frequency of lpi2c clock */
#define LPI2C_CLOCK_FREQUENCY ((CLOCK_GetFreq(kCLOCK_Usb1PllClk) / / (LPI2C_CLOCK_SOURCE_DIVIDER + 1U))
#define LPI2C_MASTER_CLOCK_FREQUENCY LPI2C_CLOCK_FREQUENCY
#define EXAMPLE_I2C_MASTER ((LPI2C_Type *)EXAMPLE_I2C_MASTER_BASE)
#define I2C_MASTER_SLAVE_ADDR_7BIT 0x7EU
#define I2C_BAUDRATE 100000U
#define I2C_DATA_LENGTH 7U
/*******************************************************************************
* Variables
******************************************************************************/
uint8_t g_master_txBuff[I2C_DATA_LENGTH];
uint8_t g_master_rxBuff[I2C_DATA_LENGTH];
lpi2c_master_handle_t g_m_handle;
volatile bool g_MasterCompletionFlag = false;
volatile bool g_MasterNackFlag = false;
static void lpi2c_master_callback(LPI2C_Type *base, lpi2c_master_handle_t *handle, status_t status, void *userData)
{
if (status == kStatus_LPI2C_Nak)
{
g_MasterNackFlag = true;
}
else
{
g_MasterCompletionFlag = true;
/* Display failure information when status is not success. */
if (status != kStatus_Success)
{
PRINTF("Error occured during transfer!\n");
}
}
}
int main(void) {
lpi2c_master_transfer_t masterXfer = {0};
status_t reVal = kStatus_Fail;
/* Init board hardware. */
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
/* Init FSL debug console. */
BOARD_InitDebugConsole();
#endif
/*Clock setting for LPI2C*/
CLOCK_SetMux(kCLOCK_Lpi2cMux, LPI2C_CLOCK_SOURCE_SELECT);
CLOCK_SetDiv(kCLOCK_Lpi2cDiv, LPI2C_CLOCK_SOURCE_DIVIDER);
PRINTF("\r\nLPI2C board2board interrupt example -- Master transfer.\r\n");
//* Set up i2c master to send data to slave*/
/* First data in txBuff is data length of the transmiting data. */
g_master_txBuff[0] = I2C_DATA_LENGTH - 1U;
for (uint32_t i = 1U; i < I2C_DATA_LENGTH; i++)
{
g_master_txBuff[i] = i-1;
}
PRINTF("Master will send data :");
for (uint32_t i = 0U; i < I2C_DATA_LENGTH - 1; i++)
{
if (i % 8 == 0)
{
PRINTF("\r\n");
}
PRINTF("0x%2x ", g_master_txBuff[i + 1]);
}
PRINTF("\r\n\r\n");
lpi2c_master_config_t masterConfig;
/*
* masterConfig.debugEnable = false;
* masterConfig.ignoreAck = false;
* masterConfig.pinConfig = kLPI2C_2PinOpenDrain;
* masterConfig.baudRate_Hz = 100000U;
* masterConfig.busIdleTimeout_ns = 0;
* masterConfig.pinLowTimeout_ns = 0;
* masterConfig.sdaGlitchFilterWidth_ns = 0;
* masterConfig.sclGlitchFilterWidth_ns = 0;
*/
LPI2C_MasterGetDefaultConfig(&masterConfig);
/* Change the default baudrate configuration */
masterConfig.baudRate_Hz = I2C_BAUDRATE;
LPI2C_MasterReset(EXAMPLE_I2C_MASTER);
/* Initialize the LPI2C master peripheral */
LPI2C_MasterInit(EXAMPLE_I2C_MASTER, &masterConfig, LPI2C_MASTER_CLOCK_FREQUENCY);
/* Create the LPI2C handle for the non-blocking transfer */
LPI2C_MasterTransferCreateHandle(EXAMPLE_I2C_MASTER, &g_m_handle, lpi2c_master_callback, NULL);
/* subAddress = 0x01, data = g_master_txBuff - write to slave.
start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/
uint8_t deviceAddress = 0x01U;
masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;
masterXfer.direction = kLPI2C_Write;
masterXfer.subaddress = (uint32_t)deviceAddress;
masterXfer.subaddressSize = 1;
masterXfer.data = g_master_txBuff;
masterXfer.dataSize = I2C_DATA_LENGTH;
masterXfer.flags = kLPI2C_TransferDefaultFlag;
/* Send master non-blocking data to slave */
reVal = LPI2C_MasterTransferNonBlocking(EXAMPLE_I2C_MASTER, &g_m_handle, &masterXfer);
if (reVal != kStatus_Success)
{
return -1;
}
/* Wait for transfer completed. */
while ((!g_MasterCompletionFlag) && (!g_MasterNackFlag))
{
PRINTF("wait for transfer to finish\n");
}
if (g_MasterNackFlag)
{
PRINTF("Master nacked by slave!");
g_MasterNackFlag = false;
}
g_MasterCompletionFlag = false;
PRINTF("transfer completed!");
while(1)
{
}
}
the I2C of the nxp is linked to an arduino, that plays the role of the slave. I can see on the oscillioscope that the address , subaddress, number of data and the first byte of data was sent correctly the problem start after that. Even in my arduino i have correctly received the first byte of data. i have attached the view of my oscilloscope.