I m a little confused with this driver. I have previously used I2C to read and write to registers but I m stuck trying to do this with fsl_i2c.c. I have run the sample code from the dev kit, SDK_2.2.1_LPCXpresso54114. This included the code i2c_polling_transfer and i2c_interrupt_transfer. This worked successfully and I was able to send and receive the example byte array through I2C. However I m trying to use these functions with a peripheral to write to a specific register. I m a bit mixed up as to whats defined as a register address and a register value.
For example, if I want to read from the register value of a device at an address such as 0x20. Would I do the following,
#define I2C_MASTER_SLAVE_ADDR_7BIT 0x20
#define I2C_DATA_LENGTH 1U
#define EXAMPLE_I2C_MASTER_BASE (I2C6_BASE)
#define EXAMPLE_I2C_SLAVE_BASE (I2C6_BASE)
#define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE)
#define EXAMPLE_I2C_SLAVE ((I2C_Type *)EXAMPLE_I2C_SLAVE_BASE)
g_master_buff[0] = 0x00;
I‘d highly recommend you to use the I2C_MasterTransferBlocking() to write or read the external I2C device, such as EEPROM memory device.
Hope it helps.
I managed to get this working. There was a very useful function I found on some website that helped.
void VEML6075_Init()
{
BOARD_InitI2C();
//VEML6075,0x40
I2C_MasterGetDefaultConfig(&masterConfig); /*******************************************************************************************************/
masterConfig.baudRate_Bps = I2C_BAUDRATE;
sourceClock = I2C_MASTER_CLK_FREQ;
I2C_MasterInit(EXAMPLE_I2C_MASTER_BASEADDR, &masterConfig, sourceClock); /*******************************************************************************************************/
txSize = 3;
rxSize = 0;
txData[0]=0x00;
txData[1]=0x40; // 800ms
txData[3]=0x00; ;
SetupXferRecAndExecute(I2C_ADDR_7BIT, txData,txSize, rxData, rxSize);/*******************************************************************************************************/
txSize = 1;
rxSize = 2;
txData[0]=0x0C;
SetupXferRecAndExecute(I2C_ADDR_7BIT, txData,txSize, rxData, rxSize);/*******************************************************************************************************/
}
static void SetupXferRecAndExecute(uint8_t devAddr,uint8_t *txBuffPtr,uint16_t txSize,uint8_t *rxBuffPtr,uint16_t rxSize)
{
memset(&masterXfer, 0, sizeof(masterXfer));
masterXfer.slaveAddress = VEML6075_I2C_ADDR_7BIT;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = 0;
masterXfer.subaddressSize = 0;
masterXfer.data = txBuffPtr;
masterXfer.dataSize = txSize;
masterXfer.flags = kI2C_TransferNoStopFlag;
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);/*******************************************************************************************************/
memset(&masterXfer, 0, sizeof(masterXfer));
masterXfer.slaveAddress = VEML6075_I2C_ADDR_7BIT;
masterXfer.direction = kI2C_Read;
masterXfer.subaddress = 0;
masterXfer.subaddressSize = 0;
masterXfer.data = rxBuffPtr;
masterXfer.dataSize = rxSize;
masterXfer.flags = kI2C_TransferRepeatedStartFlag;
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer); /*******************************************************************************************************/
}