0
\$\begingroup\$

I am trying to read capacitance and temperature from the AD7746 capacitance-to-digital converter, using STM32F103 and HAL I2C library (SDA and SCL pulled up with 2k and Vcc = 3.3 V). I did it before using AVR (using Codevision) and it worked fine, but now it doesn't work properly:

// ad7746 init
    HAL_I2C_Master_Transmit(&hi2c2, 144, (uint8_t*)Reset_address, 1, 100);
    HAL_Delay(1);
    HAL_I2C_Master_Transmit(&hi2c2, 144, (uint8_t*)EXC_SETUP, 2, 100);
    HAL_Delay(1);
    HAL_I2C_Master_Transmit(&hi2c2, 144, (uint8_t*)CAP_SETUP, 2, 100);
    HAL_Delay(1);
    HAL_I2C_Master_Transmit(&hi2c2, 144, (uint8_t*)CAP_DAC_A, 2, 100);
    HAL_Delay(1);
    HAL_I2C_Master_Transmit(&hi2c2, 144, (uint8_t*)CAP_DAC_B, 2, 100);
    HAL_Delay(1);
    HAL_I2C_Master_Transmit(&hi2c2, 144, (uint8_t*)CONFIGURATION, 2, 100);

and in a while() loop, I try to read data:

while (1)
  {
HAL_I2C_Mem_Read(&hi2c2,144, 4, 145, (uint8_t *)&VT1,1, 100);
HAL_Delay(1);   
HAL_I2C_Mem_Read(&hi2c2,144, 5, 145, (uint8_t *)&VT2,1, 100);
HAL_Delay(1);           
HAL_I2C_Mem_Read(&hi2c2,144, 6, 145, (uint8_t *)&VT3,1, 100);   
HAL_Delay(1);           
HAL_I2C_Mem_Read(&hi2c2,144, 1, 145, (uint8_t *)&CA1,1, 100);   
HAL_Delay(1);           
HAL_I2C_Mem_Read(&hi2c2,144, 2, 145, (uint8_t *)&CA2,1, 100);   
HAL_Delay(1);           
HAL_I2C_Mem_Read(&hi2c2,144, 3, 145, (uint8_t *)&CA3,1, 100);}

but in STMStudio I read all data 129 or 130 and they change together with the same, when I touch input of AD7746.

update:
Thanks for your advice. This is part of the AD7746 datasheet that explains write and read:

Image from AD7746 datasheet

So for reading one byte of capacitance or temperature data you must first send start bit, write 0x90, and then write the address again, send start bit, write 0x91 and then read data but I get 6 similar data.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Force yourself to ask a question and, while you are doing it consider whether the information you are providing is sufficient for someone to work out what the problem is rather than just guess (aka supplying opinions). \$\endgroup\$
    – Andy aka
    Oct 11, 2020 at 17:55
  • \$\begingroup\$ From a quick glance, I think you are misunderstanding how to use Hal_i2c_mem_read, so find the manual how it works. To correct your code, I would have to read the manual too or look at the code or at least the function prototype to know how to use it properly. \$\endgroup\$
    – Justme
    Oct 11, 2020 at 19:01

1 Answer 1

1
\$\begingroup\$

It solved! if you use just one: HAL_I2C_Mem_Read(&hi2c2,144, 4, 145, (uint8_t *)&VT1,6, 100); instead of 6 times, it read the correct 6 registers because AD7746 increases address automatically, but I can not find the HAL problem in addressing right register.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.