Working with MAX40080 not showing up right current/voltage values

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

https://gitlab.com/UJUR007/max40080

Which Arduino board do you use ?
The first step is always to run a I2C Scanner sketch to check if the sensor can be seen on the I2C bus.

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 :wink:
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.

Have you seen the Arduino code by the manufacturer of the sensor ? MaxEssentialToolkit/src/MAX40080/MAX40080.cpp at master · analogdevicesinc/MaxEssentialToolkit · GitHub
When something bad happens, they try to restart the I2C bus with a 'Wire.begin()' That is questionable programming and it has different results on different platforms.

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. :relieved: :pensive:

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..

Wire.endTransmission();
Wire.endTransmission(stop);

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.

I tried to prove that it is in the documentation, but there is a mistake in the documentation :man_facepalming:

This is the reference for the Wire library, and a link to the endTransmission() function is missing :man_facepalming: Wire - Arduino Reference

The page itself is still hanging in there but not linked to :man_facepalming: endTransmission() - Arduino Reference

The explanation is wrong though :man_facepalming: 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 :man_facepalming: The numbers have different meanings on different platforms.

Well, there is always my alternative explanation of the functions of the Wire library :smiley:

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.

https://gitlab.com/UJUR007/mpu6050_ind/-/tree/master

GitLab does not want me to see that :cry:

Now?

Yes, now I can see it, thank you. Code seems okay.

I am still facing the issue even after seeing those code made by the vendor.

Hence, if you have time and would like to comment what is going wrong you can look the example in examples folder and let me know the issue.!!

https://gitlab.com/UJUR007/max40080/-/tree/master

I'm sorry, but I don't see a problem in the code. It seems okay.

Okay. Seems like I would have to give up the project. :smiley:

No one else replied :cry: You could try StackExchange :thinking: Always be clear what you do, so if you ask there, then give a link to this topic.

Thanks, Let me try there.