-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of Wire library. #10
Comments
Hi @Koepel Your article I found very illuminating. I am currently writing code for SmartCitizen station; and having an amount of trouble with the Aux I2C Bus. The manufacturers provide no easy way to remove or replace the pullup resistors to bring some sort of order to the chaos;. I came across a possible solution in the form of a TCA 9458A I2C Multiplex board (made by Seeed). In deploying this unit; each device is connected to its own channel; and code is arranged to enable that channel when the Data Board wishes to take a reading. What I found is that the Mux appears to 'lock up' from time to time; and occasionally seems to require a power cycle to get it to communicate again. I am able to control the mux during start-up; allowing me to build a map of devices connected to each channel. I turn on one channel at a time and then go through an address discovery routine. It generally finds all of the attached devices (but sometimes misses one); But later; when readings are being taken; is when 'lockups' occur. They appear non-deterministic (random). I am looking at the call to auxWire.requestFrom(deviceAddress, ...) and wondering whether I need to tell each remote device to cease transmission using Wire.requestFrom(deviceaddress, numbytes, true); I am thinking that possibly one of the devices is handing onto the bus trying to retransmit... I surmised that possibly the MUX device was unhappy with being asked to rapidly switch channels almost continuously. I have taken measures to try to minimise channel switching; but the problem persists. If you still have an interest in this general topic; and have a mind to share a little; I wonder if you can shed some further light on this (use of an I2C mux for this purpose). |
Most I2C multiplexers connect the main I2C bus SDA to the (sub) I2C bus SDA1 with a mosfet. That mosfet acts like a switch between SDA and SDA1 and is only turned on for the low level. That means you have to combine the pullup of SDA together with the pullup of SDA1 to calculate the total pullup. The same for SCL, and that for each of the eight (sub) I2C buses. The I2C bus is not fault tolerant. Your I2C bus is not okay if it fails just once. The I2C bus was not designed to go through wires. The Grove connector by Seeed is wrong, because that causes crosstalk between SDA and SCL. If your wires are together, then please split the wires. The GND wire is just as important as SDA and SCL. If that GND wire caries the return current of a motor, then the I2C bus will never be reliable. You can also ask this on the forum.arduino.cc. Show a photo, give links to each module, tell which Arduino board is used, draw a schematic (with a pen on paper is okay) with all the lengths, and so on. Do you know that a timeout was added for the I2C bus for the Arduino Uno (for the AVR family boards). That might help to continue the sketch. |
In the file "smartcitizen-kit-20/sam/src/SckAux.cpp", in the function
getReading()
, there is a lineif (auxWire.available()<=2)
. However, the number of available bytes is never more that the number of bytes that was requested byWire.requestFrom()
. In case of an error, theWire.available()
might return zero. That if-statement is always true.Why is there is
delay(1)
after theWire.requestFrom()
?I have written about common mistakes and I have an alternative explanation of the Wire functions. Perhaps that can be useful.
On 5 november 2018 I took a closer look at the file:
.endTransmission()
after a.requestFrom()
can be removed.sendCommand()
function has the wrong sequence of the Wire library functions.The text was updated successfully, but these errors were encountered: