Other Parts Discussed in Thread: AM3357
Folks,
I'm very new with linux development env and has some questions hope you can help me out.
my linux env uses TI AM3357 and kernel 4.14.96 of linux (Linaro), with ADC081C021 for battery monitor.
//////////////////////////////////////////////////////
the KernelConfig has the follow:
CONFIG_IIO=y
CONFIG_IIO_BUFFER=y
CONFIG_IIO_KFIFO_BUF=y
CONFIG_IIO_TRIGGERED_BUFFER=y
# CONFIG_IIO_CONFIGFS is not set
CONFIG_IIO_TRIGGER=y
# Analog to digital converters
CONFIG_TI_ADC081C=y
///////////////////////////////////////////
the Device tree has
- tps: tps@2d {
- reg = <0x2d>;
+ tampbatt: adc081c@54 {
+ compatible = "ti,adc081c";
+ reg = <0x54>;
};
};
-&tscadc { +&gpio2 { + pinctrl-names = "default"; + pinctrl-0 = <&gpio2_pins>; status = "okay"; - tsc { - ti,wires = <4>; - ti,x-plate-resistance = <200>; - ti,coordinate-readouts = <5>; - ti,wire-config = <0x00 0x11 0x22 0x33>; - ti,charge-delay = <0x400>; - }; - - adc { - ti,adc-channels = <4 5 6 7>; - }; };
//////////////////////////////////////////////////////////////////////////////
I see the iio:device0 listed under /sys/bus/iio/devices
when I change to iio:device0, it changed to /sys/devices/platform/ocp/44e0b000.i2c/i2c-0/0-0054/iio:device0
Q: what this path mean? I'm kind of guess the 0-0054 is from tampbatt: adc081c@54 in the devicetree but don't know what the others are
I guess the below adc is comment out(am I correct?) in devicetree. So it is default one channel as I only see in_voltage_raw.
- adc { - ti,adc-channels = <4 5 6 7>; - };
Q: if I want more channel , I just change the - to + to enable channel 4, 5,6,7. Otherwise it default to one channel only, right?
When I do a ls -al command, I see the below:
/sys/devices/platform/ocp/44e0b000.i2c/i2c-0/0-0054/iio:device0 # ls
buffer in_voltage_scale scan_elements
current_timestamp_clock name subsystem
dev of_node trigger
in_voltage_raw power uevent
Q: Why do I see in_voltage_raw instead in in_voltage0_raw. There is no 0(zero) append to voltage. Is this normal?
When I do # cat in_voltage_raw, it returns 0.
my app code to read the DAC as follows. The result is zero as I don't have the battery installed yet.
int output_fd; 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"); int * exit; pthread_exit(exit); } while (1) { /* read ADC voltage */ int readResult = read(output_fd, payload, BUF_SIZE); LOG( LL_INFO, "ADC output is %s readResult = %d \n",payload, readResult); usleep(40000); } close(output_fd);
Q: Is my code above is the right way the user space code should read the DAC conversion value? If I want to program the ADC081C021 with High/Low and Alert Limit, how do I do that. Is there an example I can reference?
I have read through these links http://software-dl.ti.com/processor-sdk-linux/esd/docs/latest/linux/Foundational_Components/Kernel/Kernel_Drivers/ADC.html
but don't see how to program the ADC081C021 with High/Low and Alert Limit in User Space code (my C code).
Very appreciate any help.
-Tom