[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [oc] I2C slave source help
- To: cores@opencores.org
- Subject: Re: [oc] I2C slave source help
- From: Colin Marquardt <c.marquardt@alcatel.de>
- Date: Tue, 05 Nov 2002 07:50:56 +0100
- In-Reply-To: <200211041913.gA4JDRO21619@www.lampret.com> (ckh827@hotmail.com'smessage of "Mon, 4 Nov 2002 18:13:27 -0100")
- Keywords: sda,std,start,logic,signal,count,end,data,scl,startnow,process,fixme
- References: <200211041913.gA4JDRO21619@www.lampret.com>
- Reply-To: cores@opencores.org
- Sender: owner-cores@opencores.org
- User-Agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2(sparc-sun-solaris2.8)
ckh827@hotmail.com writes:
> 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.
I took 7 minutes to clean up the style a bit and made some coding
style comments, without even trying to run it through a compiler
or understanding what it is actually doing. Maybe that helps you
already. Check for "!!!" and "FIXME", and do a diff against your
original code to see what I changed.
entity backlightI2C is
port (sda : inout std_logic := 'Z';
scl : in std_logic; -- !!! why was this inout?
dataout : out std_logic_vector(7 downto 0));
end backlightI2C;
-- !!! architecture is not really behavioral but more RTL:
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 DATA : std_logic_vector(7 downto 0);
begin
sdacheck : process(sda)
begin
---------------------------------------------
if sda'event then
if (scl = '1' and sda = '0') then
startnow <= '1';
elsif (scl = '1' and sda = '1') then
stopnow <= '1';
-- FIXME: else missing
end if;
end if;
end process;
sclkk : process(scl)
variable count : natural := 0;
begin
-- !!! no reset?
if (scl'event and scl = '0') then
if (startnow = '1') then
start <= '1';
elsif (stopnow = '1') then
start <= '0';
count := 0;
-- FIXME: missing else
end if;
-- FIXME: missing default assignments (e.g. selected)
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 =>
start <= '0';
count := 0;
if (data = "11100001") then
selected <= '1';
sda_o <= '0';
else
sda_o <= 'Z';
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