Hi Sir,
I have give below my code for ads1114 writing and reading data from it with HAL i2c library for STM32L4S9AII board. But I get values not consistently.
So, please refer it and help me.
Thank you.
// Function "init_ADS1114" initializes ads1114 and read reset value of Config Register.
void init_ADS1114(void)
{
bool stat = true;
uint8_t rdd3[2];
hal_stat = HAL_I2C_Master_Transmit(&hi2c3, (0x48 << 1), 0x00, 1, 50); // I2C transmit 1 byte SLAVE ADDRESS + Write and read ACK status
if(hal_stat != HAL_OK)
{
return stat = false ;
}
hal_stat = HAL_I2C_Master_Transmit(&hi2c3, (0x48 << 1), 0x00, 1, 50); // I2C transmit 1 byte Address pointer register and read ACK status
if(hal_stat != HAL_OK)
{
return stat = false ;
}
hal_stat = HAL_I2C_Mem_Read(&hi2c3, 0x48 << 1, 0x01, 1, rdd3, 2, 100); // Read default value of config register
}
int16_t ADS_Result = 0;
int16_t start_ADS_1114(void)
{
uint16_t wrt =0x8483; // Configuration value for Configuration reg
uint8_t ADS_RAW[2] = {0};
bool status;
hal_stat = HAL_I2C_Mem_Write(&hi2c3, 0x48 << 1, 0x01, 1, &wrt, 2, 100); writing value to config register (0x8483 = 15bit - Start a single conversion,14:12 bits - MUX[2:0] - 000 : AINP = AIN0 and AINN = AIN1 (default),
11:9 bits - PGA[2:0] - 010 : FSR = ±2.048 V (default),8-bit- MODE - 0 : Continuous-conversion mode,7:5 bits - DR[2:0] - 100 : 128 SPS (default),4 bit - COMP_MODE - 0 : Traditional comparator (default), 3 bit - COMP_POL - 0 : Active low (default), 2 bit -COMP_LAT - 0 : Nonlatching comparator . The ALERT/RDY pin does not latch when asserted(default) , 1:0 bit - COMP_QUE[1:0] - 11 : Disable comparator and set ALERT/RDY pin to high-impedance (default) )
HAL_Delay(50);
hal_stat = HAL_I2C_Mem_Read(&hi2c3, 0x48 << 1, 0x01, 1, ADS_RAW, 2, 50); //reading the value in config register
status = (ADS_RAW[1] & (1 << 7))?1:0 ; // checking for 15 bit OS for device conversion status
while(status != 1); // waiting till OS bit is set
hal_stat = HAL_I2C_Mem_Read(&hi2c3, 0x48 << 1, 0x00, 1, &ADS_Result, 2, 100); // reading ADC data from conversion register
return ADS_Result;
}