Forums » Req. Waijung 1 Tech Support »
Reading data from INA219 Sensor
Added by Chandima Jayaneththi (จันทิมา) over 3 years ago
How to get readings from INA219 using STM32F4 (Waijung 1) blockset?
Replies (1)
RE: Reading data from INA219 Sensor - Added by Chandima Jayaneththi (จันทิมา) over 3 years 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.
ina219.pdf | View ina219.pdf | 1.31 MB | |||
slave_address_ina219.png | View slave_address_ina219.png | 15.5 KB | |||
ina219_regs.png | View ina219_regs.png | 49.1 KB | |||
INA219_Demo.slx | INA219_Demo.slx | 36.2 KB | |||
i2c_sensor_data_results.png | View i2c_sensor_data_results.png | 85.6 KB | |||
config_subsystem.png | View config_subsystem.png | 24.3 KB | |||
reading_subsystem.png | View reading_subsystem.png | 61.2 KB |