You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-58Lines changed: 83 additions & 58 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,89 @@ The SPI master and SPI slave are simple controllers for communication between FP
4
4
5
5
**The SPI master and SPI slave controllers support only SPI mode 0 (CPOL=0, CPHA=0)!**
6
6
7
-
The SPI master and SPI slave controllers were simulated and tested in hardware. If you have a question or you have a tip for improvement, send me an e-mail or create a issue.
7
+
The SPI master and SPI slave controllers were simulated and tested in hardware. I use the GHDL tool for CI: automated VHDL simulations in the GitHub Actions environment ([setup-ghdl-ci](https://github.com/ghdl/setup-ghdl-ci)). If you have a question or you have a tip for improvement, send me an e-mail or create a issue.
8
+
9
+
## SPI master
10
+
11
+
### Generics:
12
+
13
+
```vhdl
14
+
CLK_FREQ : natural := 50e6; -- set system clock frequency in Hz
15
+
SCLK_FREQ : natural := 5e6; -- set SPI clock frequency in Hz (condition: SCLK_FREQ <= CLK_FREQ/10)
16
+
WORD_SIZE : natural := 8; -- size of transfer word in bits, must be power of two
17
+
SLAVE_COUNT : natural := 1 -- count of SPI slaves
18
+
```
19
+
20
+
### Ports:
21
+
22
+
```vhdl
23
+
CLK : in std_logic; -- system clock
24
+
RST : in std_logic; -- high active synchronous reset
25
+
-- SPI MASTER INTERFACE
26
+
SCLK : out std_logic; -- SPI clock
27
+
CS_N : out std_logic_vector(SLAVE_COUNT-1 downto 0); -- SPI chip select, active in low
28
+
MOSI : out std_logic; -- SPI serial data from master to slave
29
+
MISO : in std_logic; -- SPI serial data from slave to master
30
+
-- INPUT USER INTERFACE
31
+
DIN : in std_logic_vector(WORD_SIZE-1 downto 0); -- data for transmission to SPI slave
32
+
DIN_ADDR : in std_logic_vector(natural(ceil(log2(real(SLAVE_COUNT))))-1 downto 0); -- SPI slave address
33
+
DIN_LAST : in std_logic; -- when DIN_LAST = 1, last data word, after transmit will be asserted CS_N
34
+
DIN_VLD : in std_logic; -- when DIN_VLD = 1, data for transmission are valid
35
+
DIN_RDY : out std_logic; -- when DIN_RDY = 1, SPI master is ready to accept valid data for transmission
36
+
-- OUTPUT USER INTERFACE
37
+
DOUT : out std_logic_vector(WORD_SIZE-1 downto 0); -- received data from SPI slave
38
+
DOUT_VLD : out std_logic -- when DOUT_VLD = 1, received data are valid
39
+
```
40
+
41
+
### Simulation:
42
+
43
+
A simulation is prepared in the ```sim/``` folder. You can use the prepared TCL script to run simulation in ModelSim.
44
+
```
45
+
vsim -do spi_master_tb_msim_run.tcl
46
+
```
47
+
48
+
Or it is possible to run the simulation using the [GHDL tool](https://github.com/ghdl/ghdl). Linux users can use the prepared bash script to run the simulation in GHDL:
49
+
```
50
+
./spi_master_tb_ghdl_run.sh
51
+
```
52
+
53
+
## SPI slave
54
+
55
+
### Generics:
56
+
57
+
```vhdl
58
+
WORD_SIZE : natural := 8; -- size of transfer word in bits, must be power of two
59
+
```
60
+
61
+
### Ports:
62
+
63
+
```vhdl
64
+
CLK : in std_logic; -- system clock
65
+
RST : in std_logic; -- high active synchronous reset
66
+
-- SPI SLAVE INTERFACE
67
+
SCLK : in std_logic; -- SPI clock
68
+
CS_N : in std_logic; -- SPI chip select, active in low
69
+
MOSI : in std_logic; -- SPI serial data from master to slave
70
+
MISO : out std_logic; -- SPI serial data from slave to master
71
+
-- USER INTERFACE
72
+
DIN : in std_logic_vector(WORD_SIZE-1 downto 0); -- data for transmission to SPI master
73
+
DIN_VLD : in std_logic; -- when DIN_VLD = 1, data for transmission are valid
74
+
DIN_RDY : out std_logic; -- when DIN_RDY = 1, SPI slave is ready to accept valid data for transmission
75
+
DOUT : out std_logic_vector(WORD_SIZE-1 downto 0); -- received data from SPI master
76
+
DOUT_VLD : out std_logic -- when DOUT_VLD = 1, received data are valid
77
+
```
78
+
79
+
### Simulation:
80
+
81
+
A simulation is prepared in the ```sim/``` folder. You can use the prepared TCL script to run simulation in ModelSim.
82
+
```
83
+
vsim -do spi_slave_tb_msim_run.tcl
84
+
```
85
+
86
+
Or it is possible to run the simulation using the [GHDL tool](https://github.com/ghdl/ghdl). Linux users can use the prepared bash script to run the simulation in GHDL:
87
+
```
88
+
./spi_slave_tb_ghdl_run.sh
89
+
```
8
90
9
91
## Table of resource usage summary:
10
92
@@ -28,60 +110,3 @@ Please read [README file of SPI loopback example design](example/README.md).
28
110
The SPI master and SPI slave controllers are available under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
29
111
30
112
Please read [LICENSE file](LICENSE).
31
-
32
-
# SPI master
33
-
34
-
## Table of generics:
35
-
36
-
Generic name | Type | Default value | Generic description
37
-
---|:---:|:---:|:---
38
-
CLK_FREQ | natural | 50e6 | System clock frequency in Hz.
39
-
SCLK_FREQ | natural | 5e6 | Set SPI clock frequency in Hz (condition: SCLK_FREQ <= CLK_FREQ/10).
40
-
WORD_SIZE | natural | 8 | Size of transfer word in bits, must be power of two
0 commit comments