i²C Wire.endTransmission(); returns 2 or 3

Hello together,
I solved a lot of my problems by reading other topics here, but now I have no idea any more.
I have the sensors MS5803-01BA and MS5805-02BA01. According to the datasheet the communications and the commands are the same.
I can ask from both the included calibration coefficients (to shorten the code, I just choose one coefficient as example). When I read out the pressure/or temperature I have no problem with MS5803-01BA.
With MS5805-02BA01 I get NACK back from the sensor.
I marked the problem part red in the code.
At Wire.endTransmission(); as return I get 2, if I cancel the delay bevore I get 3.
I already tried with all other OSR rate (options given by the sensor attached)

If I change just the adress to the other sensor with otherwise unchanged code, I get no error.
Does anybody have an idea what to try?
Thank you in advance! :slight_smile:

commands-sensor.PNG

mini-bsp-i2c.ino (1.38 KB)

commands-sensor.PNG

Please keep the beginTransmission-write-endTransmission together. Such as here:

  Wire.beginTransmission(kl);
  Wire.write(0b10100010);
  Wire.endTransmission();

If you need a delay, then you can put that before or after those three lines.

How much delay is needed after a reset ?
You can start with 1 second:

  //reset sequence - for the start (or at any unkown kondition)
  Wire.beginTransmission(kl);
  Wire.write(0b11110);
  Wire.endTransmission();
  delay( 1000);        // <--- delay for the device to reset

What happens if you use this sketch: https://github.com/ControlEverythingCommunity/MS5805-02BA01/tree/master/Arduino

Thank you for the fast answer.

If I ran the code as it is, I get:
Temperature in Celsius : 134507.82 C
Temperature in Fahrenheit : 242146.07 F
Pressure : 655.47 mbar

If I print the return from ADC read there as well I get:
Wire.endTransmission from selected data register 2
Temperature in Celsius : 134507.82 C
Temperature in Fahrenheit : 242146.07 F
Pressure : 1216.03 mbar

Could it be, that I have a hardware problem in connection, even if the coefficient reading works and a i²C scanner finds the adress correctly?

silviii:
Could it be, that I have a hardware problem in connection, even if the coefficient reading works and a i²C scanner finds the adress correctly?

Yes, that is possible. Especially if you connect a 5V Arduino board (such as the Arduino Uno) with a 5V I2C bus to a 3.3V sensor with a 3.3V I2C bus, then anything is possible. In that case, you might already have damaged the sensor.
It is also possible with a pullup resistor that is too weak or too strong.

Can you have a glance at this: How to make a reliable I2C bus · Koepel/How-to-use-the-Arduino-Wire-library Wiki · GitHub.

To be sure that you have real data from the sensor, you could test the return value of Wire.endTransmission() and Wire.requestFrom().
Wire.endTransmission() returns and error code. It should be zero.
Wire.requestFrom() returns the number of read bytes. It is zero when there was a problem. It should be the same as the number of requested bytes.

If the sensor is damaged, then you need a new sensor and a 3.3V Arduino board, or a I2C level shifter.
Do you use the bare sensors or a module with those sensors ? Can you give a link to where you bought the modules ?

I use a an Arduino Mega 2560 Pro where I connected the Sensors to 3.3V
When reading ADC (with the commnd (0b0):
Wire.endTransamission give 2
Wire.requestForm give 0
in the other cases (reading out coefficients)
When reading ADC (with the commnd (0b0):
Wire.endTransamission give 0
Wire.requestForm give 2 (the number of requested bytes.

I use the bare sensors, the resistance I choose as it is told in the datasheet and the cable length is realy short (few centimeter) I use the bare sensors and soldered all with 0.25mm² wires.

When Wire.requestFrom() returns zero, that means for normal sensors that the sensor did not acknowledge to its I2C address. Some sensors get confused and keep SDA low, then a few SCL pulses can take it out of it.

Manufacturer’s page of the MS5803-01BA : https://www.te.com/usa-en/product-CAT-BLPS0038.html, with datasheet.
Manufacturer’s page of the MS5805-02BA01 : https://www.te.com/usa-en/product-CAT-BLPS0015.html, with datasheet.

The Arduino Mega 2560 is the only Arduino board with 10k pullup resistors from SDA to 5V and from SCL to 5V.
As far as I know, there is no Arduino Mega 2560 Pro. The name “Arduino” may only be used for official Arduino boards. It is not allowed to sell something as “Arduino” when it is not made by Arduino.

Do you have a Robodyn Mega 2560 Pro ? https://robotdyn.com/mega-2560-pro-embed-ch340g-atmega2560-16au.html.
In the schematic are R7 and R9 pullup resistors to 5V, but the value is unspecified !

Let’s assume this:

  • Robodyn has also 10k pullup resistors to 5V.
  • The ATmega2560 has 30k internal pullup resistors to 5V.
  • You have 10k pullup to 3.3V.
  • There is nothing else on the I2C bus.
    Then you have a voltage divider. The resulting voltage for SDA and SCL is 4.27V.
    That is too much for the sensor. The maximum for SDA and SCL is 100% VDD according to the datasheet.

It is possible that Robodyn did not use 10k pullup resistors. Perhaps they are omitted on the board or perhaps they are lower than 10k.
If you have also other things on the I2C bus, then there can be more pullup resistors to 5V.
Did you take a glance at my page at Github ?

The best solution is to buy new sensors and a 3.3V Arduino board. Try to get that working. If that works well, then you can try the old sensors with the 3.3V board to check if they are really damaged.

Sorry for the late answer, I had some issues with my account.

Thank you for the hint to check my hardware, even if some commands work fine. My GND was not connected properly, now I have no error anymore!

:sunglasses:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.