Jump to content
I2Cdevlib Forums



Recommended Posts

Looking at 1.0.5 Arduino docs on Wire library, I think the proper way for reads are:





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.  




Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...