library ieee;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_unsigned.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
entity hexx is
port (
spi_dout : out STD_LOGIC;
spi_clk : in std_logic;
clk : in std_logic;
spi_cs : in std_logic;
spi_rst : in std_logic;
spi_din : in STD_LOGIC
);
end hexx;
architecture behavior of hexx is
signal spi_cs_d1, spi_cs_d2: std_logic;
signal spi_cs_f_edge : std_logic;
signal spi_clk_d1 : std_logic;
signal spi_clk_d2 : std_logic;
signal spi_clk_r_edge : std_logic;
signal spi_clk_f_edge : std_logic;
signal number : integer range 0 to 7;
signal tx_shift_reg : std_logic_vector(7 downto 0);
signal rx_shift_reg : std_logic_vector(7 downto 0);
begin
process(clk, spi_rst)
begin
if(spi_rst = '1') then
spi_cs_d1 <= '1';
spi_cs_d2 <= '1';
spi_clk_d1 <= '0';
spi_clk_d2 <= '0';
elsif rising_edge(clk) then
spi_cs_d1 <= spi_cs;
spi_cs_d2 <= spi_cs_d1;
spi_clk_d1 <= spi_clk;
spi_clk_d2 <= spi_clk_d1;
end if;
end process;
spi_cs_f_edge <= spi_cs_d2 and (not spi_cs_d1); --SPI CS 信号下降沿
spi_clk_r_edge <= spi_clk_d1 and (not spi_clk_d2); --SPI CLK 信号上升沿
spi_clk_f_edge <= spi_clk_d2 and (not spi_clk_d1); --SPI CLK 信号下降沿
process(clk, spi_rst)
begin
if(spi_rst = '1') then
number <= 0;