Read KTD2026 registers without tx command

Hi,

I need to read the registers of the KTD2026 IC as specified in the datasheet.

In short I have to send a read command with the device address (0x30), the address of the register I want to read (0x00 for example) and then I expect the register value from the device.

However, I can't do this because I have to insert a write command first and then the read command (see the code below):

int TwiTx(uint8_t address, uint8_t const * p_data, uint8_t length)
{
	int ret;
	struct i2c_msg msg;
	msg.buf = p_data;
	msg.len = length;
	msg.flags = I2C_MSG_WRITE;

	k_mutex_lock(&i2c_mutex, K_FOREVER);
	ret = i2c_transfer(i2c_dev, &msg, 1, address);
	k_mutex_unlock(&i2c_mutex);

	return ret;
}

int TwiRx(uint8_t address, uint8_t * p_data, uint8_t length)
{
	int ret;
	struct i2c_msg msg;
	msg.buf = p_data;
	msg.len = length;
	msg.flags = I2C_MSG_READ;

	k_mutex_lock(&i2c_mutex, K_FOREVER);
	ret = i2c_transfer(i2c_dev, &msg, 1, address);
	k_mutex_unlock(&i2c_mutex);

	return ret;
}

bool readRegister(uint8_t addr, uint8_t * data)
{
	if (TwiTx(0x30, &addr, 1) != 0)
	{
		return false;
	}

	if (TwiRx(0x30, data, 1) != 0)
	{
		return false;
	}

	return true;
}

int main()
{
...
    // Read register 0x00: Reset/Control register.
    if (readRegister(0x00, &data) == false)
    {
        printf("ERROR\n");
    }
...
}

In fact, reading the register fails.

How do I read the registers as indicated by the datasheet?
Thanks.

Parents Reply Children
Related