Hi,
I suppose that you can call the low level i2c function to implement the commands: I2C slave address plus write + sub-address + repeated start + I2C slave address plus read + reading data with the I2C_MasterTransferBlocking() api function.
Because this is a blocking function, it uses polling mode instead of interrupt mode, I suppose that you can disable interrupt before calling the function, after the api function has complete, then enable interrupt when you call it in a realtime OS.
The following function is in fsl_i2c.c in SDK driver for LPC family.
BTW, can you tell us the part number you are using? for example LPC, Kinetis or i.mxrt
Hope it can help you
BR
XiangJun Roing
/*!
* brief Performs a master polling transfer on the I2C bus.
*
* note The API does not return until the transfer succeeds or fails due
* to arbitration lost or receiving a NAK.
*
* param base I2C peripheral base address.
* param xfer Pointer to the transfer structure.
* retval kStatus_Success Successfully complete the data transmission.
* retval kStatus_I2C_Busy Previous transmission still not finished.
* retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
* retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
* retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
*/
status_t I2C_MasterTransferBlocking(I2C_Type *base, i2c_master_transfer_t *xfer)
{
status_t result = kStatus_Success;
uint32_t subaddress;
uint8_t subaddrBuf[4];
int i;
assert(xfer != NULL);
/* If repeated start is requested, send repeated start. */
if (0U == (xfer->flags & (uint32_t)kI2C_TransferNoStartFlag))
{
if ((xfer->subaddressSize) != 0U)
{
result = I2C_MasterStart(base, xfer->slaveAddress, kI2C_Write);
if (result == kStatus_Success)
{
/* Prepare subaddress transmit buffer, most significant byte is stored at the lowest address */
subaddress = xfer->subaddress;
for (i = (int)xfer->subaddressSize - 1; i >= 0; i--)
{
subaddrBuf[i] = (uint8_t)subaddress & 0xffU;
subaddress >>= 8;
}
/* Send subaddress. */
result =
I2C_MasterWriteBlocking(base, subaddrBuf, xfer->subaddressSize, (uint32_t)kI2C_TransferNoStopFlag);
if ((result == kStatus_Success) && (xfer->direction == kI2C_Read))
{
result = I2C_MasterRepeatedStart(base, xfer->slaveAddress, xfer->direction);
}
}
}
else if ((xfer->flags & (uint32_t)kI2C_TransferRepeatedStartFlag) != 0U)
{
result = I2C_MasterRepeatedStart(base, xfer->slaveAddress, xfer->direction);
}
else
{
result = I2C_MasterStart(base, xfer->slaveAddress, xfer->direction);
}
}
if (result == kStatus_Success)
{
if ((xfer->direction == kI2C_Write) && (xfer->dataSize > 0U))
{
/* Transmit data. */
result = I2C_MasterWriteBlocking(base, xfer->data, xfer->dataSize, xfer->flags);
}
else
{
if ((xfer->direction == kI2C_Read) && (xfer->dataSize > 0U))
{
/* Receive Data. */
result = I2C_MasterReadBlocking(base, xfer->data, xfer->dataSize, xfer->flags);
}
}
}
if (result == kStatus_I2C_Nak)
{
(void)I2C_MasterStop(base);
}
return result;
}