Код: Выделить всё
-- SPI tranmitte/recieve
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
ENTITY SPI IS
PORT(
clk:std_logic;--clock
wr:in std_logic;-- data write
sdin:in std_logic;--serial input pin
DI:in std_logic_vector(7 downto 0);--data input
DO:out std_logic_vector(7 downto 0);--data output
sout:out std_logic;--serial output
Bend:out std_logic--end serial exchange
);
END SPI;
ARCHITECTURE spiex OF SPI IS
BEGIN
PROCESS(clk,wr)
variable cnt:unsigned(2 downto 0):="000";
variable bf:std_logic_vector(7 downto 0);
BEGIN
if(wr='0')then
cnt:="111";
bf:=DI;--write data in buffer
Bend<='0';
else
if(rising_edge(clk))then
bf(7 downto 1):=bf(6 downto 0);
bf(0):=sdin;
sout<=bf(7);
if(cnt="000")then
Bend<='1';
end if;
cnt:=cnt-1;
end if;
DO<=bf;
end if;
end process;
end spiex;Моделирование работы в ModelSim