I am trying to exchange data via I2C with TI's IC in MKL03Z32CAF4, and I am using fsl_i2c.c driver to create the code.
I am in an infinite loop with I2C and cannot solve the problem.
First of all, I am trying to use the
I2C_MasterGetDefaultConfig(&masterConfig);
masterConfig.baudRate_Bps = 100000U;
sourceClock = CLOCK_GetFreq(I2C0_CLK_SRC);//48000000;
I2C_MasterInit(I2C0, &masterConfig, sourceClock);
After doing the following, I did the following code to do READ only.
masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;
masterXfer.direction = kI2C_Read;
masterXfer.subaddress = (uint32_t)reg_ad;
masterXfer.subaddressSize = 1;
masterXfer.data = rxBuff;
masterXfer.dataSize = datasize - 1;
masterXfer.flags = kI2C_TransferDefaultFlag;
I2C_MasterTransferBlocking(I2C0, &masterXfer);
But I feel that I2C is not working properly because it enters an infinite loop in the while() of I2C_MasterTransferBlocking().
If anyone knows a solution, please let me know.
By the way, the following code has an infinite loop at while().
/* Clear all status before transfer.
I2C_MasterClearStatusFlags(base, kClearFlags);
/* Wait until the data register is ready for transmit.
while (! (base->S & kI2C_TransferCompleteFlag))//(base->S & (uint8_t)kI2C_BusBusyFlag)//
{
}
Translated with www.DeepL.com/Translator (free version)