I2C send memory address in read operation


I'm trying to implement a comunication with a I2C device. I have a RA6M4 microcontroller and just one slave device on I2C.

The write operation seems to be good, as far the device has a expected behaviour.

But, in read operation, i can not fulfill the sequence of the device. The sequence is like a I2C read memory:

The point is:

- If I execute the read function (R_IIC_MASTER_Read), the start, device address, read bit, and acknoledge is good, but register address is always 0xFF, like a dummy byte.

- If I execute the write function, (R_IIC_MASTER_Write), the start and device address is good, but it sends always the write bit (0).

So, how can I achieve the correct sequence? No examples found that work it.


  • Hello,

    first, thanks all for helping me in this issue.

    The datasheet of my led drive is this: KTD2026-7-04h.pdf

    At this device, I can do writes, so at this moment I can put a led ON and OFF.

    Just to be sure, i copy again the entire function readreg of example provided here, and check the values of TRANSFER_SIZE, RECEIVE_SIZE and TRANSMIT_SIZE.

    The led driver has 8 bit registers, so i'm reading the values inside the function readreg (output[]) just before is copy to the value parameter, just to be sure i'm not leaving some info readed, because this function will read 2 bytes.

    To change the led ON and OFF, i'm writing to register 4, so i'm very sure of the contents of this registers: 1 when is ON, 0 when is OFF.

    After put the led ON and OFF, I call to readReg(4, data16); and i'm always getting the same values at the end of readreg function:

    Makjing some tests, If I change RECEIVE_SIZE  to 1, i get an I2C_MASTER_EVENT_ABORTED. So it remains at value 2.

    At this point, I'm pretty sure that is impossible to read this device, at least with fsp driver.

    Another thing that is boiling my head is that, when I started at programing microcontrollers (I think more than 20 years ago) I remember that reading an I2C device is a sequence like my led driver is saying. But i can not remember what devices i was working on, so I can not check that.

    After all, just for this led driver, I can skip read its registers, but will be a mark in my memories that this has no solution.

    As AZ_Renesas said, "The read operation on your datasheet cannot be implemented with RA".

    If you have some others ideas, tell me and I can check it.


  • Hello David,

    The standard method to read a slave device on I2C protocol is what suggested from IK_Renesas.

    You shared with us your code for writing on the slave device, could you please share with us  your code that you implemented, in order to read  from your slave device?

    If you could attach your whole project with FSP configuration, it would be appreciated.



  • If you search for this device on google and look at some of the other vendors forums, you will see this is a common issue.  It violates the I2C specification, leaving some to speculate the datasheet is wrong.  I would try doing a Write of 1 byte (the register address), and then do a read of 2 bytes.  I2C is not that difficult to bit-bang if you're the master, so there is always that option.  If you are simply reading back what you have written, then you might consider shadowing your values.  SInce the read operation was given very little attention in the datasheet, I suspect most users treat the device as a Write-Only.

  • Hello,

    I'm developing the code for my custom board, and is a big project. I can not share the whole project.

    The I2C code is just what I post above. Nothing more. I'm just trying and editing this file. At this moment, the only way to read is just call readreg function.

    The FSP configuration for the I2C stack is posted above too. 


  • Hello,

    this is what the function readreg you provided is doing.

    It call first to:

    R_IIC_MASTER_Write(&g_i2c_master0_ctrl, &reg, TRANSFER_SIZE, false);

    Reg is the register addres i want to read. TRANSFER_SIZE equals 1.

    after this is sent ok, then call to:

    R_IIC_MASTER_Read(&g_i2c_master0_ctrl, output,RECEIVE_SIZE, false);

    RECEIVE_SIZE equals 2.

    After read your post, i search too other forums and you are right, this is out of I2C protocol.

    Since this is a output driver, i have no problem to just send data and no reading it. It's so strange found a device that says works with I2C and is not compliant.

    Thanks again for the support.