用 CPLD设计所构成的CPI接口系统具有简洁、可靠等优点,是一种行之有效的设计途径。很多技术杂志和网站上,都有不少用CPLD设计PCI常规传输系统的文章。但用这些方法在MzxPlusII、Fundition等环境下进行模拟仿真时,其产生的时序往往与PCI规范有很大出入。虽然 Altera 等公司推出PCI核可以直接使用,但这样的内核占用CPLD资源较多,且能适配的器件种类少,同时价格也高,在实际设计应用中有很大的局限性。因此,使用通用型CPLD器件设计简易型PCI接口有很大的现实意义。在Compact接口的CPLD设计中,笔者根据PCI总线传输时序来进行状态机构造,并使用 VHDL语言进行功能模拟和定时分析,从而达到了预期目的。用该方法设计的CPLD-PCI接口既可支持PCI常规传输,也可支持PCI猝发传输,而且在系统编程和下载器件方面,效果也都很好。
iic 总线在设计时要看你所使用的器件的传输或接收时序
只要会一个
其他的都一样
以下是我在一本书上看到的
只给你部分
你看看就会用了
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity reciver is
port(reset,clk:in std_logic;
sda,scl:inout std_logic;
rd:out std_logic;
tdata:in std_logic_vector(7 downto 0);
rdata:out std_logic_vector(7 downto 0));
end reciver;
architecture one of reciver is
signal rdatai:std_logic_vector(7 downto 0);
type state is (start,transmit,ack,sub,ack1,start1,slave,ack2,reading,ack3);
signal current:state;
begin
process(clk,reset)
variable count:integer range 0 to 40;
variable cnt:integer range 0 to 8;
begin
if reset='1'then
sda<='1';scl<='1';rdata<="00000000";current<=start;cnt:=8;count:=0;
elsif clk'event and clk='1' then
case current is
when start=>count:=count+1;
case count is
when 1=>sda<='1';
when 2=>scl<='1';
when 3=>sda<='0';
when 4=>scl<='0';
when 10=>count:=0;current<=transmit;
when others=>null;
end case;
when transmit=>count:=count+1;
case count is
when 1=>sda<=tdata(cnt);
when 2=>scl<='1';
when 3=>scl<='0';
when 4=>cnt:=cnt-1;count:=0;
if cnt=0 then cnt:=8;current<=ack;rd<='1';
else current<=transmit;rd<='0';
end if;
when others=>null;
end case;
when ack=>count:=count+1;
case count is
when 1=>sda<='0';
when 2=>scl<='1';
when 3=>scl<='0';
when 4=>current<=sub;count:=0;
when others=>null;
end case;
when sub=>count:=count+1;
case count is
when 1=>sda<=tdata(cnt);
when 2=>scl<='1';
when 3=>scl<='0';
when 4=>cnt:=cnt-1;count:=0;
if cnt=0 then cnt:=8;current<=ack1;rd<='1';
else current<=sub;rd<='0';
end if;
when others=>null;
end case;
when ack1=>count:=count+1;
case count is
when 1=>sda<='0';
when 2=>scl<='1';
when 3=>scl<='0';
when 4=>current<=start1;count:=0;
when others=>null;
end case;
when start1=>count:=count+1;
case count is
when 1=>sda<='1';
when 2=>scl<='1';
when 3=>sda<='0';
when 4=>scl<='0';
when 5=>current<=slave;count:=0;
when others=>null;
end case;
when slave=>count:=count+1;
case count is
when 1=>sda<=tdata(cnt);
when 2=>scl<='1';
when 3=>scl<='0';
when 4=>cnt:=cnt-1;count:=0;
if cnt=0 then cnt:=8;current<=ack2;rd<='1';
else current<=sub;rd<='0';
end if;
when others=>null;
end case;
when ack2=>count:=count+1;
case count is
when 1=>sda<='0';
when 2=>scl<='1';
when 3=>scl<='0';
when 4=>current<=reading;count:=0;
when others=>null;
end case;
when reading=>count:=count+1;
case count is
when 1=>sda<='1';
when 4=>scl<='1';
when 8=>rdatai(cnt)<=sda;
when 10=>scl<='0';
when 12=>cnt:=cnt-1;count:=0;
if cnt=0 then cnt:=8;current<=ack3;rd<='1';
else current<=reading;rd<='0';
end if;
when others=>null;
end case;
when ack3=>count:=count+1;
case count is
when 1=>sda<='0';
when 2=>scl<='1';
when 3=>scl<='0';
when 4=>rdata<=rdatai;current<=start;count:=0;
when others=>null;
end case;
end case;
end if;
end process;
end architecture;