Skip to main content
FD.1
Associate
Jun 12, 2020 1:03 PM UTC
Solved

How to implement repeated start for HAL_I2C_Mem_Read and HAL_I2C_Mem_Write?

Hello,

i want to communicate with an AD7998, to convert 8 analog to digital channels. The communication i use is I2C. I am using the HAL library.

According to the adc manual i need a repeated start, after writing to the address pointer byte. So i had tried to use HAL_I2C_Mem_Read, but that isn't working.

Are there other functions in the i2c HAL library to implement a repeated start?

Thanks.

This topic has been closed for replies.
Pavel A.
Pavel A.Best answer
Jun 12, 2020 6:14 PM UTC

Yes, HAL_I2C_Mem_Read does a repeated start. If it doesn't work, check parameters. Use a logic analyzer.

-- pa

3 replies

Pavel A.
Pavel A.Best answer
Jun 12, 2020 6:14 PM UTC

Yes, HAL_I2C_Mem_Read does a repeated start. If it doesn't work, check parameters. Use a logic analyzer.

-- pa

Piranha
Principal III
Jun 13, 2020 4:19 AM UTC

So, your approach is, if something doesn't work, then:

  1. Don't fix the actual problem. Instead try something other.
  2. Choose randomly one feature (repeated start) and try to find a "solution" for it.

And, as you can see, that careless approach doesn't work... Instead there are two other approaches that actually work - either you carefully check everything or take an oscilloscope or logic analyzer and debug it.

FD.1
FD.1Author
Associate
Jun 13, 2020 6:57 AM UTC

Hi,

thanks for your reply. It works now. My ADC just didn't transfer the register values correctly. I disconnected it from the supply for a while, now it works as it should.

@ Pavel A. Good to know that, thank you.