1

It says in the description of the function:

Registers a function to be called when a slave device receives a transmission from a master.

So when does it exactly called? I guess it's not been called for each byte, but its the meaning of receiving transmission from the master. Does it called for each byte? When the master use transmissionBegin? transmissionEnd?

  • The functions are beginTransmission and endTransmission, not what you had. – Nick Gammon May 22 '16 at 20:49
1

It is called at the end of the reception of the entire packet - i.e., when the slave receives the final STOP bit. It is passed the number of bytes received (which is the number of bytes you requested since I2C has no way of being able to work out if it is actually receiving real data - see here) as the only parameter so you know how many bytes you can then read from the internal buffer without overflowing it.

  • Yes, so after endTransmission it would be called - once all of the bytes in the buffer have been transferred, or the transfer failed. – Nick Gammon May 22 '16 at 20:50
  • It is passed the number of bytes received - on the AVR versions of the library at least, you get the number of bytes you asked for or zero. I have a discussion about this here. – Nick Gammon May 22 '16 at 20:52
  • It looks like they fixed it on SAM... I guess the AVR's I2C module isn't as capable as the SAM one and can't work out if it failed to receive or not. – Majenko May 22 '16 at 20:56
  • I don't know how they did that, because the slave doesn't control the clock and can't therefore raise a stop condition. The master is clocking out clock pulses, and reading the results. If the slave stops sending the master just receives 1-bits because of the pull-up resistor. – Nick Gammon May 22 '16 at 20:59
  • I guess it may never receive an ACK from the slave though after the last byte has been sent by it - so it would time out. – Majenko May 22 '16 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.