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
  • Hi,

    I am a bit unsure about the KTD2026 datasheet, as the read operation there is odd. A normal I2C register read operation is in form of a write with the register address followed by a read. This is a very common operation, so you have helper functions for this in Zephyer (i2c_reg_read_byte()/i2c_reg_read_byte_dt()). Have you by any chance been in contact with Kinetic about this? It would be interesting to know if this is an issue in the documentation.

    I see another thread included a driver for KTD2026, so perhaps that can be used as a reference.

Reply
  • Hi,

    I am a bit unsure about the KTD2026 datasheet, as the read operation there is odd. A normal I2C register read operation is in form of a write with the register address followed by a read. This is a very common operation, so you have helper functions for this in Zephyer (i2c_reg_read_byte()/i2c_reg_read_byte_dt()). Have you by any chance been in contact with Kinetic about this? It would be interesting to know if this is an issue in the documentation.

    I see another thread included a driver for KTD2026, so perhaps that can be used as a reference.

Children
No Data
Related