cancel
Showing results for 
Search instead for 
Did you mean: 

Problems reading correct data from AD7746 using STM32 I2C HAL library

Shp.1
Associate II

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.

This is part of the AD7746 datasheet that explains write and read:

0693W000004JenCQAS.jpgSo 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.

2 REPLIES 2
nico
Associate II

Is "Reset_address" a pointer? if not ship the address of this uint variable into this Hal function

Shp.1
Associate II

In datasheet mention if stop occur, address set to 0x00

but in HAL I changed the address from 1 to 6 in this code but all 6 data are similar