I have a problem with reading the ADC conversion result in normal mode i.e the address pointer register is set to 0(zero). When I try to read the result, only the first reading returns the conversion result, all the following reading are zeros. I read the ADC081C021 data sheet. It indicates after a read, it would start the conversion again. Thus I assume I can continue to read it.
But if I close the file and open again for every reading, it would returns a none-zero result. Is that suppose to be the way to read the ADC in normal mode(single shot mode)
my linux env uses TI AM3357 and kernel 4.14.96 of linux (Linaro), with ADC081C021 for battery monitor.
Here is the code that I try to read the ADC conversion results.
char adcName[] = "/sys/bus/iio/devices/iio\:device0/in_voltage_raw";
output_fd = open(adcName, O_RDWR);
if (output_fd < 0) {
LOG( LL_INFO, "failed to open ADC \n");
pthread_exit(NULL);
}
for (int i = 0; i < 10; i++)
{
/* read ADC */
LOG(LL_INFO, "WRITE ADDRESS POINTER REG \n");
addrPointerReg = CONVERSION_RESULT; // CONVERSION_RESULT is zero
write(output_fd, &addrPointerReg, sizeof(Address_Pointer_Reg));
int ret = read(output_fd, &conversionResultReg, sizeof(Conversion_Result_Register));
LOG(LL_INFO, "ADC output converResult = %d ret = %d \n",
conversionResultReg.conversionResult, ret);
conversionResultReg = {0}
}
close(output_fd);
Thanks
-Tom