Project

General

Profile

Reading data from INA219 Sensor

Added by Chandima Jayaneththi (จันทิมา) 3 months ago

How to get readings from INA219 using STM32F4 (Waijung 1) blockset?


Replies (1)

RE: Reading data from INA219 Sensor - Added by Chandima Jayaneththi (จันทิมา) 3 months ago

Before using the I2C block, the salve address of the INA219 should be found in the datasheet. The datasheet is attached herewith (ina219.pdf). The slave address of the INA 219 which is used for the following demo model file is 0x40(b1000000). The slave address can be selected according to A0 and A1 pin configuration as in the following figure.

The slave address which is shown in the datasheet is a 7-bit address. But when the salve address is given to the I2C block it should be a 8-bit address (by shifting one bit left to the 7-bit address). For the above breakout board it should be 0x80 (0x40 << 1 = 0x80). Once the slave address is set, then you have to configure the sensor parameters such as Bus voltage range, PGA gain and ADC resolution. You can change those parameters according to your application. After that you can start to get the readings (Bus voltage, Current and Power) by accessing the each register as follows.

In the following demo, the data will be sent via UART and you can see the data using a serial monitor

Demo model file: INA219_Demo.slx

In the attached model, sensor configuration is done in the sensor_init subsystem.

And the getting sensor data is done in the read_data subsystem.

    (1-1/1)