I have an Atmega328 programmed using the Arduino software and libraries (but is standalone on on a board in the TSOP package) without bootloader and with ISP programming). I am using the Wire library to act as an I2C peripheral, where I implement (and register) the requestEvent and receiveEvent callbacks.

Is it possible to determine, either during the requestEvent callback or after it at some point, how many bytes were read by the master before it sent a NACK?

1 Answer 1


You can't.

The master will have to inform the slave how many bytes to transfer, or the master will have to query the slave how many bytes there are to receive.

  • I understand that the protocol doesn't specify that. I'm interested in getting the number of bytes that were actually sent by the slave until the master sent a NACK instead of an ACK, as I specified originally in the question (be it through another callback, by calling a Wire function, etc), after the send actually completes.
    – nanofarad
    Aug 29, 2016 at 21:25
  • *actually completes at the physical level, after the master sends the NACK.
    – nanofarad
    Aug 29, 2016 at 21:31
  • You have no access to that level of information through the API. You can count how many times your callback is called, but that's as close as you get. You would have to work out some way of knowing what is the first transfer though.
    – Majenko
    Aug 29, 2016 at 21:33
  • You would have to work entirely at the register level and implement your own I2C code.
    – Majenko
    Aug 29, 2016 at 21:33
  • OK, that clarification answers the question perfectly.
    – nanofarad
    Aug 29, 2016 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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