Closed RobTillaart closed 2 years ago
Problem reported/discussed here:
Fix the code patch when MBED endTransmission() is updated. If not patch will stay until better solution is available.
@ratio-x I'm closing this issue as it can take a long/unknown time before it is fixed in MBED. The MS5611 library works with the patch so there are no actual problems anymore. When fixed in MBED, it needs to be verified before patch can be removed. (probably the patch becomes MBED version dependent first)
Feel free to post new insights (even if closed) or reopen if needed.
(this is a summary of an earlier discussion by e-mail, better to archive the essence here) The NANO 33 BLE is an processor using MBED toolchain.
Problem
The MS5611 cannot be seen on the I2C bus
This prevents to check if the device is connected in the device.begin() call during the setup of the project. Note that the device will work as it should if one ignores the return value of begin().
Analysis
The isConnected() call and I2C scanners just put addresses on the I2C bus and expect an ACK when a device recognizes its address. The MS5611 does this well on AVR and ESP but not on MBED.
Note that on the internet there were similar an related problems mentioned without a solution.
(many tests and mails later a possible cause is found in the endTransmission() code of MBED ....Arduino15\packages\arduino\hardware\mbed_nano\2.7.2\libraries\Wire\Wire.cpp
If there are no bytes in the transmitBuffer the MBED returns the value of read() If there are bytes in the transmitBuffer the MBED returns the value of write()
Other endTransmission() implementations known - AVR / ESP - always use the write() even if the transmitBuffer is empty
(usedTxBuffer == 0)
The rationale why MBED does this differently is unknown.
Patch / workaround
The library is patched so if an NANO 33 BLE is addressed it adds an write(0) in the isConnected() code (0.3.5)
https://github.com/RobTillaart/MS5611/blob/master/MS5611.cpp
This forces the write path in endTransmission() and the device returns the ACK expected.
WARNING: Although this works it is not a solution as it is unknown how devices in general will react on this extra byte,
Thoughts about a solution
The patch above is a workaround that is not the right solution so more investigations / discussions are needed to solve this.
a test shows this works well for the MS5611 but unknown if this causes any problems with other devices.
A generic solution could be that the Wire library is extended with a call, which returns if the address exist on the I2C bus.