ccxtechnologies / nuttx

Apache NuttX is a mature, real-time embedded operating system (RTOS)
https://nuttx.apache.org/
Apache License 2.0
0 stars 0 forks source link

INA260 Power Sensor not getting configured #9

Closed CFD2 closed 3 years ago

CFD2 commented 3 years ago

Summary

Writing to configuration register of the power sensor and reading from it results in default (a.k.a. reset) value 0x6127. Can write to another register of the power sensor (Alert Limit Register @ 0x07) just fine.

Description

Sensor address: 0x40 Configuration register address: 0x00 Default register value: 0x6127

Added a debug statement to read from config register right after writing to it:

imxrt_ina260initialize: Initializing INA260 ina260_access: start_register_address: 0x00 data_length: 2 register_value: 0x02 (0x0002) ret: 0 ina260_access: Reading back config register: ina260_access: start_register_address: 0x00 data_length: 2 register_value: 0x61 (0x2761) ret: 0 ina260_register: (addr=0x40) registered at /dev/ina260

INA260 writing config register crop
CFD2 commented 3 years ago

From datasheet, p.21:

The Configuration Register can be read from at any time without impacting or affecting the device settings or a conversion in progress. Writing to the Configuration Register halts any conversion in progress until the write sequence is completed resulting in a new conversion starting based on the new contents of the Configuration Register (00h).

The register is available for read/write operations at any time.

CFD2 commented 3 years ago

On the screenshot in the header message, the format of I2C message is incorrect for writing to registers. It is similar to reading from the register (i.e. change the register pointer, then supply data MSB and LSB, figure 26 on the screenshot from the datasheet).

Instead, when writing to a register, the address needs to be followed by the destination register location and then followed by the data to be written into the register.

From the datasheet, p.19:

Screenshot_20210715_121400

In other words, writing to registers should look more like this (addr. 40, reg. 00, data 02 07):

ina260 reg write proper