Skip to main content
Visitor II
December 22, 2020
Question

I2C - I want to read data from the register by the HAL (HAL_I2C_Mem_Read) but 8 bit every rime is LOW but should be HIGH.

  • December 22, 2020
  • 2 replies
  • 3863 views

Hello everybody!!)) I spent a few days already, try to decide this problem, this reason I decided to ask here.

I can write data to register by command HAL_I2C_Mem_Write, but can not read, because 8 register is low

 uint8_t adress_read1 = 0x43;

 uint8_t status = 0x1F;

 uint8_t status_readed;

HAL_I2C_Mem_Read(&hi2c4, adress_read, status, 1, (int8_t*)&status_readed, 1, 10);

You can see it the photo

0693W000006GZQKQA4.jpgI try used differents types for variables, different times, different lengths for variables, different speeds for I2C but the result every rime same. 

That interesting, with command HAL_I2C_Master_Receive - works without problem, but with this command, I can only read data and can not read registers. Where can be an error, please help me?

    This topic has been closed for replies.

    2 replies

    Super User
    December 22, 2020

    What does that bit represent? Why do you think it should be 1?

    IRakh.1Author
    Visitor II
    December 23, 2020

    1 - for reading, 0 - for writing

    Graduate II
    December 23, 2020

    This is not the bit you identified. The Slave address goes into the High Order 7-bits, you don't need to manage the R/W bit at this level.​

    Super User
    December 23, 2020

    The way HAL_I2C_Mem_Read works is it first writes the address of the register it wants to read, then it reads that data. Otherwise how would the chip know which address to send? There should be multiple byte transactions here and you're only showing one of them.

    It should be more clear if you look at the datasheet of the device you're interfacing with. Here is a read transaction from a random I2C EEPROM datasheet I found, which shows the R/W bit changing values at different places in the transaction.

    0693W000006GlNhQAK.png 

    IRakh.1Author
    Visitor II
    December 24, 2020

    thank you so much, problem was decided

    Technical Moderator
    December 29, 2020

    Hi @IRakh.1​ ,

    If the problem was resolved thanks to the last reply of TDK, please select it as a "Best Answer" so that this request is marked as resolved.

    -Amel