[email=always@(posedge]always@(posedge[/email] sck)
begin
if((cs==0)&(rw==0)) //MOSI enable
begin
spi_in[0:0]=sdi;
spi_in=spi_in<<1;
end
end
[email=always@(negedge]always@(negedge[/email] sck)
begin
if(msg_spiout_trg)
begin
spi_out=8'h01; //TXD assignment.U can put a variable instead of it.
msg_spiout_fb=1;
end
else msg_spiout_fb=0;
if((cs==0)&(rw==1)) //MISO enable
begin
sdo=spi_out[7:7];
spi_out=spi_out<<1;
end
end
[email=always@(posedge]always@(posedge[/email] cs) //cs=1 means Master write complete
begin
ledout=~spi_in; //use data received,for example...
end
[email=always@(negedge]always@(negedge[/email] rw or posedge msg_spiout_fb) //Message of SPI MISO BUFF
begin
if(rw==0)
msg_spiout_trg=1;