IIC中的应答和非应答

IIC中的应答和非应答

        应答是I2C非常重要的机制,是不一定要弄清。它在工作中涉及的范围包括总线仲裁(多主)、正常的数据通信。这个问题在常见总线里是比较特别的,应当深入详细地了解。让我们先整理一下这个问题。

1 确认应答和非应答的定义和解释:

·  应答:是一个低电平信号。

·  非应答:是一个高电平信号,也许,叫做应答非更合适。

·  两个信号的明显不同是来源不同。应答信号是当前从器件发出的,而非应答信号是由当前主器件发出,再者方向是相反的。

·  应答或非答的时钟,都由当前主器件发生。

·  (这 句出自何立民的《I2C总线应用系统设计》)原述:“应答信号在第9个时钟上出现,接收器输出低电平为应答信号(A),输出高电平则为非应答信号 (/A)”,“由于某种原因,被控器不产生应答时,如被控器正在进行其它处理无法接收总线上的数据时,必须释放总线,将数据线置高电平,然后主控器可通过产生一个停止信号信号来比终止数据传输。”“当主控器接收数据时接收到最后一个数据字节后,必须给被控器发送一个非应答位(/A),使被控器发送器释放数 据线,以便主控制(注:应当是主控器,不是主控制)发送停止信号从而终止数据传输。”

  

图1 


图2 

调试程序的过程中出现了一些问题,在进过修改和改正之后一共总结了一下几点需要明确的问题: **1.所写的应答函数和非应答函数是主机发送给从机的确认和非确认信号** 2.在写模式的时候,接受的应答信号是从机发送的应答,主机时被动接收方,所以在写完一个字节后将SDA设置为输入口,主机等待从机发送的应答信号。 3.写数据的时候,master每发送完八个数据位,slave如果含有空间接受下一个字节,应当回答“Ack”,数据传输完成和确认后,然后发送停止信号。 4.写数据时,写入的是从设备的子地址,不能和从设备的地址混淆。 5.读数据的时候,slave每发送完八个数据位,如果继续读取下一个字节,主机应该回答“ACk”,当从机收到“Ack”时提示从设备准备下一个数据,如果主机不继续读取更多字节,那么主机应该回答“Nack”以提示从设备准备接受stop信号, 6.按照时序的逻辑,在传送完八位数据后应将SDA线拉高释放,准备传输应答和非应答信号。 7.从器件的地址默认是0xC0, 8.在读取数据时需要将SDA线由输出模式转换为输入模式,读完数据以后SDA又需变回输出模式,由主机发送应答或非应答信号。

I2C规范中关于应答的内容

7.2 Acknowledge

Data transfer with acknowledge is obligatory. The acknowledge-relatedclock pulse is generated by the master. The transmitter releases the SDA line(HIGH) during the acknowledge clock pulse.

The receiver must pull down the SDA line during the acknowledge clockpulse so that it remains stable LOW during the HIGH period of this clock pulse(see Fig.7). Of course, set-up and hold times (specified in Section 15) mustalso be taken into account.

Usually, a receiver which has been addressed is obliged to generate anacknowledge after each byte has been received, except when the message startswith a CBUS address (see Section 10.1.3).

When a slave doesn’t acknowledge the slave address (for example, it’sunable to receive or transmit because it’s performing some real-time function),the data line must be left HIGH by the slave. The master can then generateeither a STOP condition to abort the transfer, or a repeated START condition tostart a new transfer.

If a slave-receiver does acknowledge the slave address but, some timelater in the transfer cannot receive any more data bytes, the master must againabort the transfer. This is indicated by the slave generating thenot-acknowledge on the first byte to follow. The slave leaves the data lineHIGH and the master generates a STOP or a repeated START condition.

If a master-receiver is involved in a transfer, it must signal the end ofdata to the slave- transmitter by not generatingan acknowledge on the last bytethat was clocked out of the slave. The slave-transmitter must release the dataline to allow the master to generate a STOP or repeated START condition.

 


  • 10
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值