RYIP Posted June 7, 2013 Report Share Posted June 7, 2013 Looking at 1.0.5 Arduino docs on Wire library, I think the proper way for reads are: beginTransmission(devID) write(addr) endTransmission requestFrom(addr, count) while (Wire.available()) { data = Wire.read() } There's no need for beginTransmission before the requestFrom. Also, there is no need for endTransmission. In the current I2Cdev.cpp, by placing the extra beginTransmission you just added an extra entry to the write buffer. When you issue the endTransmission (which is AFTER requestFrom), you are generating a new write transaction with ONLY the devID. In fact, the current code behaves differently for Due and Uno. For the Due code, not only generate an extra unneeded writing of the devID, if also writes an unneeded address. Quote Link to comment Share on other sites More sharing options...
Jeff Rowberg Posted June 8, 2013 Report Share Posted June 8, 2013 Thanks, RYIP. I will look into this; I have a Due, but I haven't actually used it for anything yet (included testing with I2Cdev). I'm all for making things simpler and more efficient though, and as soon as I get a chance, possibly this weekend or next weekend. Quote Link to comment Share on other sites More sharing options...
RYIP Posted June 10, 2013 Author Report Share Posted June 10, 2013 I think the function names are unnecessarily misleading. Anyway, to allow burst writes to a I2C slave, the "beginTransmission" is like setting up the buffer on AVR. Then the subsequent "writes" places transactions on the write buffer (not talking to the I2C slave yet). And the "endTransmission" actually opens up the flood gate to allow the transactions to go down to the I2C slave. However, in the case of burst read, "requestFrom" already includes the device ID as well as the number of bytes to read. As such, once it sees this request, AVR (or SAM) can already initiated the transaction to the slave. The extra "beginTransmission" and "endTransmission" surrounding the "requestFrom" merely flush out the write buffer AFTER the read transaction (since the flushing of write buffer is initiated by "endTransmission"). Uno (1.0.5) and Due (1.5.2) behave differently when you flush a empty write buffer. Uno merely sends out one write transaction with the device ID. But then Due sends out a write transactionb with the device ID followed by a write transaction with the address. Personally, I think the Due way is the more "correct" way. Quote Link to comment Share on other sites More sharing options...
bechtold Posted November 12, 2014 Report Share Posted November 12, 2014 Hey, I have a problem with this behavior for the mpr121. If you could checkout this thread would be great: http://www.i2cdevlib.com/forums/topic/218-arduino-wire-endtransmission-readbytes-not-working/ Cheers bechtold Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.