Hardware Reference
In-Depth Information
39
--Generate 5MHz clock for SPI circuit:
40
process (clk)
41
variable counter1: natural range 0 to 5;
42
begin
43
if rising_edge(clk) then
44
counter1:= counter1 + 1;
45
if counter1=5 then
46
spi_clk <= not spi_clk;
47
counter1:= 0;
48
end if;
49
end if;
50
end process;
51
52
--FSM (complete SPI circuit):
53
process(spi_clk, rst)
54
variable i: natural range 0 to 75;
55
variable j: natural range 0 to 7;
56
begin
57
58
--Pointers (i, j):
59
if rst='1' then
60
i:= 0;
61
j:= 0;
62
elsif falling_edge(spi_clk) then
63
if (i=0 and wr='0' and rd='0') or (i=42 and wr='0') or
64
(i=75 and rd='0') then
65
i:= 0;
66
elsif(i=0andwr='1')or(i>0andi<34)or(i>=43andi<67)then
67
i:= i + 1;
68
elsif i=0 and rd='1' then
69
i:= 43;
70
elsif (i>=34 and i<=41) or (i>=67 and i<=74) then
71
if j/=7 then
72
j:= j + 1;
73
else
74
j:= 0;
75
i:= i + 1;
76
end if;
77
end if;
78
end if;
79
80
--LUT (for outputs):
81
--Default values:
82
SSn <= '0';
83
SCK <= spi_clk;
84
MOSI <= '-';
85
--Other values:
86
case i is
87
when 0 =>
88
SSn <= '1';
89
SCK <= '0';
90
when 1 to 8 =>
91
MOSI <= WREN_opcode(8-i);
92
when 9 =>
93
SSn <= spi_clk;
Search WWH ::




Custom Search