cancel
Showing results for 
Search instead for 
Did you mean: 

I2C read specific register without repeated start

CBras
Associate

Hello,

I'm interfacing the KTD2026 RGB sensor.

Writing to the device's registers works with normal HAL I2C functions.

The problem i'm facing is reading the device's registers which from datasheet should be done the following way:

0693W00000Y85fQQAR.pngI have tried both HAL_I2C_Master_Receive and HAL_I2C_Mem_Read but none of them produces this kind of I2C flow.

HAL_I2C_Master_Receive does not provide any register address to read from and HAL_I2C_Mem_Read do a write operationen followed by a repeated start with a read which not works.

Do i really need to make my own I2C driver for reading this device?

3 REPLIES 3

Which STM32?

The device (KTD2026) obviously violates the I2C specification, which very specifically prescribes that direction of bytes after the address byte is given by the R/W bit, read NXP(ex-Philips)'s UM10204, chapter 3.1.10 The target address and R/W bit. (There is an exception, when 10-bit addressing is used, the second byte is always written as the second byte of the address - but that's not the case here, 10-bit addresses are specifically marked by the first byte starting with 0b11110).

As the I2C modules in STM32 are built according to the standard, your only option is to bit-bang the protocol.

JW

AScha.3
Chief III

i read from ES9038 DAC, using the HAL_I2C_Mem_Read() , is working ok. and seem same type of access:

0693W00000Y87baQAB.pngadress/read/register/data(to read) .

example: (on H743 )

HAL_I2C_Mem_Read(&hi2c2,0x91, 67, 1, &reg_status, 1, 5 );

If you feel a post has answered your question, please click "Accept as Solution".

If it works with that function, then most likely the diagram is wrong. Actually it's not entirely wrong, it just shows the sequence for write command only.