-
Notifications
You must be signed in to change notification settings - Fork 117
/
Loopback.v
69 lines (64 loc) · 1.56 KB
/
Loopback.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
`timescale 1ns/1ps
module SPI_loopback
#(
parameter CLK_FREQUENCE = 50_000_000 , //system clk frequence
SPI_FREQUENCE = 5_000_000 , //spi clk frequence
DATA_WIDTH = 8 , //serial word length
CPOL = 0 , //SPI mode selection (mode 0 default)
CPHA = 0 //CPOL = clock polarity, CPHA = clock phase
)
(
input clk ,
input rst_n ,
input [DATA_WIDTH-1:0] data_m_in ,
input [DATA_WIDTH-1:0] data_s_in ,
input start_m ,
output finish_m ,
output [DATA_WIDTH-1:0] data_m_out ,
output [DATA_WIDTH-1:0] data_s_out ,
output data_valid_s
);
wire miso ;
wire mosi ;
wire cs_n ;
wire sclk ;
spi_master
#(
.CLK_FREQUENCE (CLK_FREQUENCE ),
.SPI_FREQUENCE (SPI_FREQUENCE ),
.DATA_WIDTH (DATA_WIDTH ),
.CPOL (CPOL ),
.CPHA (CPHA )
)
u_spi_master(
.clk (clk ),
.rst_n (rst_n ),
.data_in (data_m_in ),
.start (start_m ),
.miso (miso ),
.sclk (sclk ),
.cs_n (cs_n ),
.mosi (mosi ),
.finish (finish_m ),
.data_out (data_m_out )
);
SPI_Slave
#(
.CLK_FREQUENCE (CLK_FREQUENCE ),
.SPI_FREQUENCE (SPI_FREQUENCE ),
.DATA_WIDTH (DATA_WIDTH ),
.CPOL (CPOL ),
.CPHA (CPHA )
)
u_SPI_Slave(
.clk (clk ),
.rst_n (rst_n ),
.data_in (data_s_in ),
.sclk (sclk ),
.cs_n (cs_n ),
.mosi (mosi ),
.miso (miso ),
.data_valid (data_valid_s ),
.data_out (data_s_out )
);
endmodule