This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/INA223: Linux kernel driver & application for INA223

Part Number: INA223
Other Parts Discussed in Thread: INA226, INA219, INA233

Tool/software: Linux

Hi Sir,

We are using the INA223 for voltage/current monitoring on one of our arm boards.

It is interfaced on I2C BUS and the board is up with linux kernel v4.1.15

I am wondering whether there is any linux driver and user space application available to spped up our development on using this device ?

your help is greatly appreciated. Looking forward for your response.

Please do let me know if you need more information.

Thanks,

Siva

  • Hello Siva,

    We do not have any linux drivers. Although you can most likely find linux code to communicate with the INA223 or other devices online. I found this source code online using a quick and simple search.

    code.woboq.org/.../ina2xx.c.html

    This is for the INA226, INA219, and others, but all of our digital current shunt monitors are very similar with their I2C communication protocol. Hope this helps.

    Sincerely,
    Peter Iliya
    Current Sensing Applications
  • Siva,

    We have driver code at our website, see link belw. Seems like the same thing compared to what I sent earlier.

    www.ti.com/.../ina2xxsw-linux

    Sincerely,
    Peter Iliya
    Current Sensing Applications
  • Hi Peter,

    Thanks for your input. 

    I tried to cross compile the same code. But i get  the following error

    drivers/hwmon/ina2xx.c: In function ‘ina2xx_probe’:

    drivers/hwmon/ina2xx.c:447:27: error: implicit declaration of function ‘of_device_get_match_data’; did you mean ‘of_device_get_modalias’? [-Werror=implicit-function-declaration]
    chip = (enum ina2xx_ids)of_device_get_match_data(&client->dev);

    If you are aware of this error earlier. Please do let me know in first place.

    Looks like needs some modification in the code of adding a header or so..

    Thanks,

    Siva

     

  • Actually, the code that you provided earlier through google search doesn't support the device tress
    But the code provided in the latest post supports the device tress.
    My linux kernel v4 is based on device tress to detect the devices.
  • This doesn't support device tress
  • Getting the compilation errors !!!
    drivers/hwmon/ina2xx.c: In function ‘ina2xx_probe’:

    drivers/hwmon/ina2xx.c:447:27: error: implicit declaration of function ‘of_device_get_match_data’; did you mean ‘of_device_get_modalias’? [-Werror=implicit-function-declaration]
    chip = (enum ina2xx_ids)of_device_get_match_data(&client->dev);
  • Siva,

    I am sorry to read of your problem. I am no linux expert, but when I look through the library "<linux/of_device.h>" online I do not see a function called "of_device_get_match_data". Maybe try replacing this function with following options until the code compiles:

    of_device_get_modalias
    of_driver_match_device

    Additionally, this driver source code was not made to include INA233, but INA233 I2C is very similar to our other devices (INA226, INA219, etc) so there may be some minor modification needed for the source code like making sure register locations are correct and adding INA233 to the "MODULE_DEVICE_TABLE".

    I hope this helps.
    Sincerely,
    Peter Iliya
    Current Sensing Applications
  • Hi Peter,

    Thanks for your support.

    Now, I Succesfully compile the driver with proper changes to device_id  and the module inserted succesfully. 

    But I donot see the corresponding folder created under /sys/class/hwmon/

    In my case, hwmon0 is the temperature zone. I can only see that folder.

    Am I in right path in usage of this driver ?

    I am not sure how to read the register values or the voltage/current values by using the driver. 

    I am able to see the device with I2C address 0x41 when I probe with i2cdetect -y 3

    Let me know  if you need more inputs, I can share the code for your reference.

    Looking forward for your help

    Thanks,

    Siva

    Thanks,

    Siva

  • Hi Siva,

    What folder are you looking for in /sys/class/hwmon? I would recommend to try sending individual read/writing commands similar to your "i2cdetect -y 3" over a command-line-interface. Whatever I2C library you are using must have i2c read and write commands.

    Best,
    Peter Iliya
    Current Sensing Applications
  • Hi Peter,

    I am not sure about the register address(configuration register) to read from i2cget

    The i2cdump gives the following values
    root@imx7d-pcm-061-2111101e:~# i2cdump 3 0x41 b
    WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-3, address 0x41, mode byte
    Continue? [Y/n] y
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    00: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    10: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    20: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    30: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    40: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    50: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    60: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    70: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    80: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    90: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    a0: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    b0: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    c0: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    d0: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    e0: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..
    f0: 00 00 00 00 05 1e 00 00 00 00 00 00 05 1e 00 00 ....??......??..

    I am not able to find the register address from the data sheet.
    So could you please provide me the configuration register address then i will read that address from i2cget.

    Basic question if i am able to handle the device from i2ctools in userspace then what's the purpose of this INA2XX driver here ?


    Thanks,
    Siva
  • Hey Siva,

    The configuration register address is 0x00. This is because this is the only register in the device. You will write to this register (0x00) in order to set gains for shunt and bus voltage measurements and to set the output mode settings (Table 1 in datasheet). Since there is only one register in the device, once the pointer is set a 0x00, then you can obtain measurements with 3-byte read commands as shown with Figure 40.

    The i2c-tools library in Linux provides a basic library to communicate with devices over the command line. The Linux driver is there to provide device-specific functions in the memory of whatever your system may be. This will make the writing firmware easier.

    Sincerely,
    Peter Iliya
    Current Sensing Applications
  • Hi Peter,

    Now I am able to see the ina223 device under

    # cat /sys/class/hwmon/hwmon0/name

    ina223
    # cat /sys/class/hwmon/hwmon0/curr1_input
    352
    # cat /sys/class/hwmon/hwmon0/in0_input
    0
    # cat /sys/class/hwmon/hwmon0/name
    ina223
    ~# cat /sys/class/hwmon/hwmon0/power1_input
    0

    in the dmesg, I can see the 

    ~# dmesg | grep ina223
    [ 0.246615] i2c i2c-3: of_i2c: register /soc/aips-bus@30800000/i2c@30a50000/ina223@41
    [ 0.246772] i2c i2c-3: client [ina223] registered with bus id 3-0041
    [ 1.871869] ina223 3-0041: probe
    [ 1.872693] ina223 3-0041: power monitor ina223 (Rshunt = 10000 uOhm)
    [ 1.877880] i2c-core: driver [ina223] registered
    [ 4.551582] ina223 3-0041: uevent
    [ 4.635567] ina223 3-0041: uevent
    [ 4.635820] ina223 3-0041: uevent
    [ 4.636053] ina223 3-0041: uevent

    Now at this stage, I am not sure how to read the current & voltage readings from the driver populated sys filesystem. Could you please assist.

    How can i change the configuration register value from the sysfs using the ina223 driver.

    Please provide me your inputs on this topic. Looking forward for your response

    Best Regards,

    Siva

  • You cannot read the current or voltage from the INA223 over I2C, it is an analog output only device, not I2C. The I2C interface is only used to select which signal is sent out of the analog output pin, you have to then sample that signal yourself.

    If you are wanting to read these values over I2C then please select one of the devices in this series that does have an internal ADC. If you would also like Linux support I would recommend one of the devices listed in the Linux driver, as these are already supported.

    Andrew

  • Hi Andrew,

    Thanks for the inputs. I am using the linux driver and lmsensor application to read the values. Below is the output

    # sensors

    ina223-i2c-0-41
    Adapter: 30a20000.i2c
    in0: +0.00 V
    in1: +0.00 V
    power1: 0.00 W
    curr1: +1.21 A

    The linux driver is for ina226. But the device on the board is ina223 . I am not sure whether i need to do any modifications in the driver to get the correct values.

    The shunt resistor value is 50000 microohms

    From the above output. It shows 0 values for in0, in1 & power1. Could you please provide your inputs where I am missing. 

    Thanking you in advance for your quick response.

    Best Regards,

    Siva

  • I am not using the i2ctools to access the device rather I am using the linux driver which takes cares of the samples.
  • The INA223 is not compatible with the INA226 driver. The INA223 cannot output the voltage or current over I2C as, unlike the INA226, it has no internal ADC. It does not matter what driver or tools you use the device will not give you the current or voltage over I2C. If you need to read the current or voltage over I2C use the INA226.

    Andrew

  • Hi Andrew,

    From the earlier posts of this thread its suggested that we can read this device through simple i2c tools and also with the linux driver. 

    But from the latest posts from you gives that we are not in right direction to access this device.

    At this stage if i want to progress with INA223 device to measure the current & Voltage readings. Do I need to connect the analog output to any ADC ?

    If so could you please point to some application note specific to INA223 device. 

    Thanking you in advance for your help. 

    Best Regards,

    Siva

  • Hi Siva,

    Yes is does look like there was some confusion in the early thread in regards to the driver compatibility.

    You are correct in that you will need to connect the analog output to an ADC. Which one you chose is depedent on your application, for instance if a lot of application processors and micro-controllers have one built in that you can attach to and read from there. If you do not have an ADC available then using an external dedicated one is probably more trouble that it is worth and you should just use the INA226 which has one built in, they are only a couple cents more.

    Thanks,
    Andrew