case state is
when setup =>
if data_ready = '1' and start_counter = "000" then
data_out<= x"41";
bit_counter <= 7;
state <= WRITE ;
return_state=SETUP;
start_counter <= "001";
SPI_done <='1';
end if;
if start_counter = "001" then
data_out<= data_max_filter(7 downto 0);
bit_counter <= 7;
state <= WRITE ;
return_state<= SETUP;
start_counter <= "010";
SPI_done <='0';
end if;
if start_counter = "010" then
data_out<= data_max_filter(15 downto 8);
state <= WRITE ;
return_state<= INIT;
start_counter <= "000";
end if;
when WRITE =>
if (bit_counter = 0) then
state <= return_state;
else
bit_counter <= bit_counter - 1;
data_out <= data_out(6 downto 0) & '1';
end if;