请教一个I2C的程序的问题
时间:10-02
整理:3721RD
点击:
我是新手,请教各位大哥,做了一个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;
//------------------------------------------------------------------------
parameterr7=8'b10101111;
parameterw7=8'b10101110;
always @(negedge sda & rst)
if (!rst)
begin
out_flag <= 0;
sda_buf <= 0;
eio<=0;
end
else
if (scl)
begin
@ (posedgescl) sda_buf[7] <= sda;
@ (posedgescl) sda_buf[6] <= sda;
@ (posedgescl) sda_buf[5] <= sda;
@ (posedgescl) sda_buf[4] <= sda;
@ (posedgescl) sda_buf[3] <= sda;
@ (posedgescl) sda_buf[2] <= sda;
@ (posedgescl) sda_buf[1] <= sda;
@ (posedgescl) 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
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;
//------------------------------------------------------------------------
parameterr7=8'b10101111;
parameterw7=8'b10101110;
always @(negedge sda & rst)
if (!rst)
begin
out_flag <= 0;
sda_buf <= 0;
eio<=0;
end
else
if (scl)
begin
@ (posedgescl) sda_buf[7] <= sda;
@ (posedgescl) sda_buf[6] <= sda;
@ (posedgescl) sda_buf[5] <= sda;
@ (posedgescl) sda_buf[4] <= sda;
@ (posedgescl) sda_buf[3] <= sda;
@ (posedgescl) sda_buf[2] <= sda;
@ (posedgescl) sda_buf[1] <= sda;
@ (posedgescl) 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
[求助]请教一个I2C的程序的问题
always @(negedge sda & rst)// 此处有误
if (!rst)
.......
else
......
[求助]请教一个I2C的程序的问题
是的
这个地方肯定不能这样些的