[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[oc] I2C slave source help




could somebody give me some comments on the I2C slave model below? it
got ping only 1 out of 20.  I tried so hard to debug it and has no
luck.  could somebody help me out.  



entity backlightI2C is
   Port (  sda : inout std_logic:= 'Z';
           scl : inout std_logic:= 'Z';
		dataout : out std_logic_vector(7 downto 0));
end backlightI2C;



architecture Behavioral of backlightI2C is

signal sda_o: std_logic;
signal clr_start:std_logic;
signal start: std_logic;
signal d_start: std_logic;
signal startnow: std_logic;
signal d_startnow: std_logic;
signal startnow1: std_logic;
signal stop : std_logic;
signal stopnow : std_logic;
signal clkstop : std_logic;
signal sigSDA: std_logic;
signal selected: std_logic;
signal selectednow: std_logic;
signal selectednow1: std_logic;
signal DATA: std_logic_vector(7 downto 0);
begin

sdacheck:process(sda)
type bool is (true,false);
variable sel : bool := false;
--variable count: integer := 0; 
variable statecount: integer := 0;
begin

---------------------------------------------
if sda'event then
if (scl = '1' and sda = '0') then
   startnow <= '1';
elsif (scl = '1' and sda = '1') then
   stopnow <= '1';
end if;
end if;
end process;

sclkk:process(scl)
variable count: integer:= 0;
begin
if (scl'event and scl = '0') then
   if (startnow = '1') then
	   start <= '1';
		--count := 0;
	
	elsif (stopnow = '1') then
	   start <= '0';
		count:=0;
	
	end if;

  if (start = '1') then
	    
	    case count is 
		           		          
		when 0 => data(7) <= sda;
		 count := 1;
                 start <= '1';
                 

		 when 1 => data(6) <= sda;
		 count := 2;
		 start <= '1';
					
		 when 2 => data(5) <= sda;
		 count := 3;
		  start <= '1';
					 

		when 3 => data(4) <= sda;
		count := 4;
		 start <= '1';
			
		when 4 => data(3) <= sda;
		count := 5;
		start <= '1';
					

		when 5 => data(2) <= sda;
		count := 6;
		start <= '1';
					
		when 6 => data(1) <= sda;
		count := 7;
		 start <= '1';
					


		when 7 => data(0) <= sda;
		count := 8;
		start <= '1';
			
                 when 8 => 
			if ((data(7) = '1') and (data(6)= '1') and (data(5)= '1') and
(data(4)= '0') and (data(3)= '0') and (data(2)= '0') and (data(1)=
'0') and (data(0)= '1')) then
			 
			 selected <= '1';
			 count := 0;
			 sda_o <= '0';
			 start <= '0';
									 
			else
			 start <= '0';
			sda_o <= 'Z'; 
			 count := 0;
									
                        ---------------------------------  
			end if;

                 when others =>
			count := 0;
			start <= '0';
                        sda_o <= 'Z'; 
		 end case;
     end if;
	  if sda_o = '0' then
         sda <= '0';
      else
        sda <= 'Z';
     end if;
 end if;


end process; 

end Behavioral;
--
To unsubscribe from cores mailing list please visit http://www.opencores.org/mailinglists.shtml