Advertisement
art_sta

Untitled

Nov 8th, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.11 KB | None | 0 0
  1.  
  2. library IEEE;
  3. use IEEE.STD_LOGIC_1164.ALL;
  4. use IEEE.NUMERIC_STD.ALL;
  5.  
  6.  
  7. entity SPI is
  8. port(
  9.        
  10.         data_out: out STD_LOGIC_VECTOR(7 downto 0);
  11.       data_in: in STD_LOGIC_VECTOR(7 downto 0);
  12.         address: in STD_LOGIC_VECTOR(2 downto 0);
  13.        
  14.         en: in STD_LOGIC;
  15.         wr_en: in STD_LOGIC;
  16.        
  17.        
  18.         mclk: in STD_LOGIC;
  19.         sclk: out STD_LOGIC;
  20.         ss_out: out STD_LOGIC;
  21.         ss_in: in STD_LOGIC;
  22.         spi_out: out STD_LOGIC;
  23.         spi_in: out STD_LOGIC
  24.        
  25.        
  26. );
  27. end SPI;
  28.  
  29. architecture zachowanie of SPI is
  30.  
  31. signal dzielnik : unsigned(1 downto 0);
  32. signal bit_counter : unsigned(2 downto 0) := b"000";
  33. signal f_sclk_signal : STD_LOGIC;
  34. signal busy: STD_LOGIC;
  35. signal state: STD_LOGIC := '0';
  36. signal address_reg: STD_LOGIC_VECTOR(2 downto 0):= "000";
  37. signal status_reg : STD_LOGIC_VECTOR(7 downto 0):= "00000000";
  38. signal conf_reg : STD_LOGIC_VECTOR(7 downto 0):= "00000000";
  39. signal shift_reg : STD_LOGIC_VECTOR(7 downto 0):= "00000000";
  40.  
  41.  
  42. begin
  43.  
  44.  
  45. process(state) begin
  46. if(rising_edge(state)) then
  47.  
  48.  
  49.  
  50.  
  51. end if;
  52. end process;
  53.  
  54.  
  55. process(shift_reg) begin
  56. status_reg(0)<='1';
  57. end process;
  58.  
  59. process(mclk) begin
  60. if(rising_edge(mclk)) then
  61.  
  62. if (state = '0') then
  63. if en = '1' and wr_en = '1' then
  64. address_reg <=address;
  65. state<='1';
  66. end if;
  67.  
  68. else
  69. state <= '0';
  70. case address_reg is
  71. when "00" => if(status_reg(0) = '0') then shift_reg(7 downto 0)<=data_in(7 downto 0); end if;  
  72. when "01" => status_reg(7 downto 0)<=data_in(7 downto 0);
  73. when "10" => conf_reg(7 downto 0)<=data_in(7 downto 0);
  74. end case;
  75.  
  76. end if;
  77.  
  78. end if;
  79. end process;
  80.  
  81.  
  82.  
  83. process(mclk) begin
  84. if(rising_edge(mclk)) then
  85.     if(dzielnik = b"11") then
  86.     dzielnik <= b"00";
  87.     else
  88.     dzielnik <= dzielnik + 1;
  89.     end if;
  90. end if;
  91.  
  92. end process;
  93.  
  94.  
  95.  
  96. process(f_sclk_signal) begin
  97. if(falling_edge(f_sclk_signal) and status_reg(0) = '1') then
  98.     if(bit_counter = 7) then
  99.     bit_counter <= b"000";
  100.     status_reg(0) <= '0';
  101.     else
  102.    
  103.     shift_reg(7 downto 1)<= shift_reg(6 downto 0);
  104.     bit_counter <= bit_counter + 1;
  105.     end if;
  106. end if;
  107. end process;
  108.  
  109.  
  110.  
  111.  
  112.  
  113. spi_out<=shift_reg(23);
  114. sclk<=not dzielnik(1);
  115. f_sclk_signal<=not dzielnik(1);
  116. end zachowanie;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement