cancel
Showing results for 
Search instead for 
Did you mean: 

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.

IRakh.1
Associate III

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?

7 REPLIES 7
TDK
Guru

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

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

1 - for reading, 0 - for writing

TDK
Guru

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 

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

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.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
IRakh.1
Associate III

thank you so much, problem was decided

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

This Best Answer metric is broken and self-serving. Most places where this works effectively is where the OP states what the remedy turns out to be, and peers vote on which response best identified the cause. Users should not be able to up-vote their own questions, and responses.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..