0
\$\begingroup\$

I'm looking at the ATMega328 datasheet and the Arduino UNO Wire/twi implementation, as well as a logic analyzer trace of a proprietary device I'm trying to send data to.

The device is trying to read anywhere from N=48 to 512 bytes. It keeps driving the clock for N packets (8-bits+ACK), but the UNO stack's interrupt only sends 32 bytes per transaction.

The spec leads me to believe that the master should NACK when it is done, but the wire code in the UNO lib state machine (for slave transmit) drives ACK/NACK when there is still data left.

This isn't clear to me: who drives ACK/NACK on the 9th bit during a slave transmit?

Thanks, PeterT

\$\endgroup\$
3
\$\begingroup\$

I am not sure if your question is focused directly on some particular feature of Arduino UNO (in that case it is bit unclear to me what are you asking), but for any I2C communication in general, it is the best to check I2C specification, in particular page 10 in current version.

Short answer to your question is: ACK/NACK bit is set by the party which just received a databyte regardless of master or slave. For slave sending data to master it is thus master who should drive SDA for ACK/NACK bit.

Particular cases when NACK should be sent instead of ACK are listed in the specification. Slave should ACK or NACK address depending on if it is its valid address and if it is willing (or able) to communicate in the moment. It should ACK any received databyte from master except when it is unable to receive any more data or byte received is in some way invalid (though, in practice, it is probably good idea to not expect any particular slave's ACK/NACK behavior here except if you have found it explicitly mentioned in the datasheet).

Master, OTOH, should ACK each byte read from slave except the last byte it is going to read in current transaction. Last byte read before issuing STOP or repeated START should be NACKed by master.

\$\endgroup\$

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.