Hi,
Since last some days I have been working with the MAX40080 I2C current sense Amplifier.
I am facing issue in correctly reading the I2C values.
As per the datasheet of MAX40080 there needs to be two 16bit configuration register which are required to be set in order to read the values.
First one is Configuration (0x00h).
I send the values in bytes as following. The PEC is enabled with both Current/voltage measurement enabled. With selected active mode and 0.5ksps sample rate.
uint8_t config[] = {0x2D, 0x5F};
The second register is the FIFO Configuration. I send the values such as the following.
tmp[0] = 0x02; tmp[1] = 0x74;
In response the current and voltage reading are always 00.
I am sure both reading and writing to I2C functions are correctly implemented. For more please see the following gitlab
Yes the sensor is there on 0x21h and also I can read the default values as per the datasheet for all the resisters. I am using ESP32s2 based PAN9520.
Could you please look the datasheet ? In the attached Page 27 where registers has been defined MAX40080 Datasheet.pdf (1003.6 KB)
We prefer that you show your whole sketch here on the forum, between code tags.
Additional information can be supplied with a link, but it is easier to talk about the order of commands and definitions such as 0x2D, 0x5F with the sketch here in a post.
On this forum, when someone says that, then there is a high chance that it is has a bug Bug: Remove the parameter from 'Wire.endTransmission()' in the functions 'writei2creg()' and 'writei2cbytes()'. You are leaving the I2C bus open. It should be closed with a STOP condition.
I'm reading and reading, but I don't understand the "Active Mode", "Selected Active Mode" and "Standby Mode".
The sensor has a Quick Command, which is not possible on many platforms:
Arduino Uno: write with no data is possible, read with no data is not possible.
Arduino + Mbed: write with no data seems to be impossible.
ESP32-S2: I don't know.
What was the manufacturer thinking ? Page 21: "Normal transactions consist of 2-byte writes and reads. However, some registers are single-byte read and one register is 4-byte read".
Could you disable the PEC ? It think it is easier without.
When a sensor has a FIFO and a INT signal, they are usually used together.
I have not read what will happen when you read only two bytes from a four-byte register.
Please read the full four bytes from the CurrentMeasurement and VoltageMeasurement register.
The datasheet is overwhelming for me at the moment, sorry.
Hi @Koepel
Thanks for ponting me out the library. I didn't know that it exists.! I has searched on google but dont know I didn't get the link you have posted.
So looking at the library I can see some configuration data. The next time I am going to try those values and have some detailed look.
When the device is turned on it is in low-power mode and we can either change that by sending the selected/active mode bits to measure the Current/Voltage values continuously.
The standby mode is when the device is not using I2C communication for more than one minute and also for this mode to remain active one of the bit must be configured in configuration register.
The Quick command part is something I have ignored and not used for now. The sensor should work without that.
Reading less register is okey than specified in communication. It will just read those first bytes. but reading more will just override the same values starting of the read sequence.
Thanks @Koepel
You don't know how important it is that you found a bug that I should remove the false parameter from endTransmission.
I was working with two different libraries for sensors. And in one of them, things worked quite well since last time. But today all of a sudden when I finished writing code for the library and tried it with lots of hours of efforts it did not work. It should have worked because last time it worked with parameter false was there.
But as soon as I removed that parameter it has again started working. Thanks! wooouuh.
I am surprised as this documentation is not there on Arduino Wire library page. While in my opinion it should be described somewhere. Fortunetely, I found it online that explains..
Parameters: stop : boolean. true will send a stop message after the last byte, releasing the bus after transmission. false will send a restart, keeping the connection active.
The explanation is wrong though When the parameter is "false", a stop is omitted and the next start will be seen as a restart condition. The Wire.endTransmission() does not generate that restart itself.
Also the number of the error codes are not that strict The numbers have different meanings on different platforms.
Thanks for explaining the concern you have. Since many time, I had the same feelings when I see wrong or not documented features which are quite important.
I had done the same when you found the bug, I looked Wire library documentation and I did not find the endTransmission() method there. But anyways I was working with MPU6050 sensor library. Now it is fine.