-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspi_slave.v
52 lines (41 loc) · 1.27 KB
/
spi_slave.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
`include "spi_defines.v"
module spi_slave (input sclk,mosi,
input [`SPI_SS_NB-1:0]ss_pad_o,
output miso);
reg rx_slave = 1'b0; //Slave recieving from SPI_MASTER
reg tx_slave = 1'b0; //Slave transmitting to SPI_MASTER
//Initial value of temp is 0
reg [127:0]temp1 = 0;
reg [127:0]temp2 = 0;
reg miso1 = 1'b0;
reg miso2 = 1'b1;
always@(posedge sclk)
begin
if ((ss_pad_o != 8'b11111111) && ~rx_slave && tx_slave) //Posedge of the Serial Clock
begin
temp1 <= {temp1[126:0],mosi};
end
end
always@(negedge sclk)
begin
if ((ss_pad_o != 8'b11111111) && rx_slave && ~tx_slave) //Negedge of the Serial Clock
begin
temp2 <= {temp2[126:0],mosi};
end
end
always@(negedge sclk)
begin
if (rx_slave && ~tx_slave) //Posedge of the Serial Clock
begin
miso1 <= temp1[127];
end
end
always@(negedge sclk)
begin
if (~rx_slave && tx_slave) //Posedge of the Serial Clock
begin
miso2 <= temp2[127];
end
end
assign miso = miso1 || miso2;
endmodule