|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
小弟用FPGA访问外部sram,用状态机实现,先向地址0x1里写了一个数2,再向地址0x2里写了一个数4,然后读地址0x1的数,始终不对!
程序如下,请各位指教:如有更好的方法请赐教!
library ieee;
use ieee.std_logic_1164.all;
entity sram is
port (
clk,rst : in std_logic;
saddr : out std_logic_vector(16 downto 0);
dataio: out std_logic_vector(15 downto 0);
sram_wrenut std_logic;--sram写使能,低有效
sram_rdenut std_logic;--sram输出使能,低有效
sdata : inout std_logic_vector(15 downto 0)
)
end sram ;
architecture behavor of i486_bus is
signal state,next_state :std_logic_vector(1 downto 0);
begin
process(clk)
begin
if rst='1'then
state<="00";
elsif clk'event and clk='1'then
state<=next_state;
end if;
end process;
process(state)
begin
case state is
when "00"=>
sram_wren<='0';--写数据
sram_rden<='1';
saddr<="00000000000000001";--地址0x1
sdata<="0000000000000100";--写入数据 4
next_state<="01";
when "01"=>
sram_wren<='0';--写数据
sram_rden<='1';
saddr<="00000000000000010";--地址0x2
sdata<="0000000000000010";----数据2
next_state<="10";
when "10"=>
sram_wren<='1';--读数据
sram_rden<='0';
saddr<="00000000000000010";--地址0x2
dataio<=sdata;--数据输出到io口上,测量该io口数据不对
next_state<="10";--循环读该地址
end case;
end process;
|
|