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/INA260: Device tree entry support

Part Number: INA260

Tool/software: Linux

Hello:

We are using INA260 in our custom design board. I have got the following module to enable in my Kernel configuration.

CONFIG_PACKAGE_kmod-hwmon-ina2xx:  
│  
│ Kernel module for ina2xx dc current monitor chips  
│  
│  
│ 
│ Symbol: PACKAGE_kmod-hwmon-ina2xx [=y]
│ Type : tristate 
│ Prompt: kmod-hwmon-ina2xx.............................. INA2XX monitoring support 
│ Location:
│ -> Kernel modules
│ -> Hardware Monitoring Support
│ -> kmod-hwmon-core.............................. Hardware monitoring support (PACKAGE_kmod-hwmon-core [=y]) 
│ Defined at tmp/.config-package.in:9152
│ Depends on: PACKAGE_kmod-hwmon-core [=y]
│ Selects: PACKAGE_kmod-i2c-core [=y] && PACKAGE_kmod-regmap [=n]

&i2c1 {
  clock-frequency = <100000>;
  pinctrl-names = "default";
  pinctrl-0 = <&pinctrl_i2c1>;
  status = "okay";

  ina260 {
    compatible = "ti,ina230";
    reg = <0x4e>;
    shunt-resistor = <10000>;
  };
};

Am I missing any DTS entry for current sense trip? or how do I assign the same?

We have to measure the power draw on the USB port, hence the Alert output from INA260 is connected to a GPIO. I believe we have to define the GPIO entry in the above structure.

Appreciate your support

Regards,

Waman Prabhu

Methode Electronics.

  • Hello Waman,

    Thanks for considering to use Texas Instruments. I am not sure I understand your problem. To define a trip point on your slave INA260, you need to send the proper series of write I2C messages from your master Microcontroller/microprocessor to configure the Mask/Enable register and the Alert Limit register. You should define the GPIO in your above code according to which GPIO pin you decide to route the INA260 ALERT to. To determine how to do that, I would recommend reading the documentation provided for the microcontroller you are using as the syntax may not be the same for every device and brand. If you are using a Texas Instruments microcontroller, we actually have example code on how to define the ports as well as how to write and read using the I2C protocol. Also if you are using a TI microcontroller and have issues with the code syntax, I would recommend posting your question under the microcontrollers forum. However, if you need help determining what bytes to write to the INA260 to properly measure your current range of interest, this current sensing forum can help you with that.
  • Hello Patrick,

    Appreciate your response.

    Sure, I'll define a GPIO for the Alert signal.

    However, if you need help determining what bytes to write to the INA260 to properly measure your current range of interest, this current sensing forum can help you with that.

    >> Please let me know what bytes need to be written for measuring the current? Can I use the Linux i2c-tools(i2cset/i2cget commands) to achieve the above statement? 

    Thanks,

    Waman Prabhu.

  • Hello Waman,

    What bytes you need is actually a broad question.  I suspect you are new to I2C protocol.  So I will start at a high level, let you proceed from that information, and then I believe we can narrow the scope of information needed specifically for your application.

    To properly measure the current, you first need to configure the device or write to the device.  You will want to write to the configuration register to set the measurement mode, the conversion times, and the averaging mode.  To configure this you will send from your master a bit stream like the one shown below.

    The slave address is determined by the device pins A0 and A1. Table 2 of the datasheet tells you how these pins should be tied to gnd, VS, SDA, or SCL depending on the address your slave INA260 will use. Note that the address is only 7 bits and not a full byte. However, the read/write bit completes the byte. Some microcontrollers split the address and R/W bit into two separate lines of code. After you have sent the address from your master device (whatever you are programming with linux), the master waits for the slave to pull the SDA line low to acknowledge it received the address bit stream. After the acknowledge, your master will need to send the address or pointer of the configuration register. The configuration register address is 00h. All register addresses can be found in Table 4 of the datasheet. After the second acknowledge from the slave, the master sends the upper and lower bytes corresponding to your desired configuration settings. To determine these settings, refer to Figure 30.

    For reading from a slave’s register, you will need send the slave address and the register address as before. However, the key difference here is the R/W bit, this will be high (for write it should be low). After the register address is sent, the master pulls the line low to acknowledge. Afterwards, the slave transmits the contents of the requested register. If you are reading the current value you will need to convert the binary bit stream to the decimal equivalent. Then you can multiply this value by the current LSB step size, 1.25mA, found in the Electrical Characteristics table of the datasheet. If you still need some help understanding the I2C protocol, I would recommend the following application note.

    As for the code, I am not super familiar with doing this in linux and cannot confirm that those commands will work for you. However, I did find this link with some example code that may help you. Yet it may require you to make some more modifications.