我最近的项目需要使用 i2c 通信,使用单个主设备和多个从设备。我知道,对于主机发送的每个数据字节(实际数据),从机以 Nack\Ack(1,0) 响应。
我对如何解释 Nack 和 ACK 感到困惑。我搜索了网络,但我没有得到关于这个的清晰图片。我的理解是这样的。
ACK-我已经成功接收到数据。向我发送更多数据。
NACK-我还没有收到数据。再次发送。
这是这样的事情还是我错了。
请澄清并提出正确的答案。
谢谢
阿米特库马尔
最佳答案
你真的应该阅读 I2C 规范 here ,但简而言之,ACK/NACK 有两种不同的情况需要考虑:
也可能是接收方有错误可以发送NACK;我不记得规范是否允许这样做。
但最重要的是,NACK 要么表示无法重试的致命情况,要么只是表示传输结束。
顺便说一句,接收设备需要更多时间来处理的情况永远不会由 NACK 指示。相反,从设备要么进行“时钟延长”(或者主设备只是延迟生成时钟),要么使用更高层的协议(protocol)来请求重试。
2019 年 6 月 8 日编辑:正如@DavidLedger 所指出的,有些 I2C 闪存设备使用 NACK 来指示闪存内部繁忙(例如,完成写入操作)。我回到 I2C 标准(见上文),发现以下内容:
There are five conditions that lead to the generation of a NACK:
No receiver is present on the bus with the transmitted address so there is no device to respond with an acknowledge.
The receiver is unable to receive or transmit because it is performing some real-time function and is not ready to start communication with the master.
During the transfer, the receiver gets data or commands that it does not understand.
During the transfer, the receiver cannot receive any more data bytes.
A master-receiver must signal the end of the transfer to the slave transmitter.
因此,这些 NACK 条件根据标准是有效的。
短延迟,特别是在单个操作中,通常会使用时钟拉伸(stretch),但较长的延迟,特别是操作之间以及无效操作,我很可能会产生 NACK。
关于i2c - I2c 总线上的 NACK 和 ACK 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37040696/