|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新手,请教各位大哥,做了一个I2C的slave的写的程序,但是仿真出来EIO的输出都是零,而不是sda的值,请各位高手指点一下
module I2Cslave(scl, sda, rst,eio);
input scl;
inout sda;
input rst;
output eio;
reg out_flag;
reg[7:0] sda_buf;
reg[7:0] eio;
reg[3:0] cnt;
reg ack;
//------------------------------------------------------------------------
parameter r7=8'b10101111;
parameter w7=8'b10101110;
always @(negedge sda & rst)
if (!rst)
begin
out_flag <= 0;
sda_buf <= 0;
eio<=0;
end
else
if (scl)
begin
@ (posedge scl) sda_buf[7] <= sda;
@ (posedge scl) sda_buf[6] <= sda;
@ (posedge scl) sda_buf[5] <= sda;
@ (posedge scl) sda_buf[4] <= sda;
@ (posedge scl) sda_buf[3] <= sda;
@ (posedge scl) sda_buf[2] <= sda;
@ (posedge scl) sda_buf[1] <= sda;
@ (posedge scl) sda_buf[0] <= sda;
if (sda_buf==w7)
begin
cnt <= (cnt+1'b1);
if ( cnt == 3'b111 )
begin
eio <= {sda_buf[6:0], sda};
cnt <= 3'b0;
sda_buf<= 8'b0;
out_flag=1;
ack<=1'b0;
end
end
else
begin
sda_buf <= {sda_buf[6:0], sda};
end
endmodule |
|