Hi,
I am using the FRDM-KV31F and I cannot receive an I2C message. Sending is OK, but it still has some issue I haven't found yet. Since I am using SDK v2, I have almost copied the demos so I don't know where the mistake is.
As far as I understood the slave datasheet, I have to send a write message with no data, just the address of the register and next send a read message with the register address and a one byte buffer for the slave response.
Here follows the code:
...
static void i2c_master_callback(I2C_Type *base, i2c_master_handle_t *handle, status_t status, void *userData)
{
/* Signal transfer success when received success status. */
if (status == kStatus_Success){
g_MasterCompletionFlag = true;
}
}
...
* Get default configuration for master. */
I2C_MasterGetDefaultConfig(&masterConfig);
/* Init I2C master. */
I2C_MasterInit(I2C0, &masterConfig, I2C_MASTER_CLK);
masterXfer.slaveAddress = I2C_BMS_ADDR;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = 0x04;
masterXfer.subaddressSize = 1;
masterXfer.data = txBuff;
masterXfer.dataSize = 1;
masterXfer.flags = kI2C_TransferNoStopFlag;
I2C_MasterTransferCreateHandle(I2C0, &g_m_handle, i2c_master_callback, NULL);
I2C_MasterTransferNonBlocking(I2C0, &g_m_handle, &masterXfer);
/* Wait for transfer completed. */
while (!g_MasterCompletionFlag){}
g_MasterCompletionFlag = false;
masterXfer.direction = kI2C_Read;
masterXfer.flags = kI2C_TransferRepeatedStartFlag;
I2C_MasterTransferNonBlocking(I2C0, &g_m_handle, &masterXfer);
/* Wait for transfer completed. */
while (!g_MasterCompletionFlag){}
g_MasterCompletionFlag = false;
...
Thanks in advance