在主机方式下,接收数据时,ISP器件必须通过启动信号生成器送出一个启动信号,然后发送从机的地址信号和读写信号。只有这样,才能在总线上发送数据。该过程由控制寄存器启动。VHDL描述如下: PROCESS(WR,CS) ——WR IS CPU WRITE SIGNAL ——CS IS THIS CHIP"S SELECT SIGNAL ADDRS:="0"; IF(Ctrreg(0)="1"AND Ctrreg(3)="1" AND SCL1="1")THEN ——Ctrreg 为控制寄存器 CLK1COUNT:="0"; SDA1:="1"; IF(CLK1 EVENT AND CLK="0")THEN IF(CLK1COUNT="3")THEN SDA1:="1"; ADDRS:="1"; Ctrreg(3):="0"; CSTA:="1"; ELSE CLK1COUNT:=CLK1COUNT+1; END IF; END IF; END IF; IF(ADDRS="1"AND SCL1 "EVENT AND SCL1="1")THEN %26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;——将数据寄存器中的数据 %26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;%26;#183;——及WR信号移位发出(略) END IF; END PROCESS;当一次通讯结束时,主机要发送停止信号。该过程同样同控制寄存器控制;当控制字第二位为"1"时,ISP器件产生停止信号。VHDL描述与启动类似。
在主机方式下,完成通讯启动和地址信号发送后便开始准备接收数据。每接收一个字节后要发出应答信号,产生一个负脉冲作为中断请求信号输出给处理器。若此时系统忙,则拉低SCL电平迫使发送机进入等待状态。从机方式下的接收与主机方式下一样。VHDL描述如下: PROCESS(SDA1) SACK:="0"; FULL1:="0"; STP:="0"; INTQ:="1"; IF(CSTA="1" AND ADDOK="1")THEN IF(SCL"1"EVENT AND SCL1="0")THEN ……——接收数据,串入并出移位(略) FULL1:="1"; END IF; END IF; IF(FULL1="1")THEN IF(RD"EVENT AND RD="1"AND SCL1"EVENT AND SCL1="0 AND BUSY="0")THEN SDA1:="0"; FULL:="0"; INTQ:="0"; ELSE SDA1:="1"; IF(CLK1"EVENT AND CLK="0" AND FULL1="0")THEN IF(CLK1COUNT"20")THEN INTQ:="1"; CLK1COUNT:="0"; ELSE CLK1COUNT:=CLK1COUNT+1; END IF; END IF; IF(SLAVE="1" AND SCL="1" AND SDA "EVENT AND SDA="1")THEN STP:="1"; CSTA:="0"; END IF; END IF; END PROCESS;