大家好,我是fpga新手,最近在做fpga采集数据存入外部sram:IS61LV2568中,最后从SRAM中读出数据,通过spi传给单片机进行处理。 但调了近2周,还是一团糟。单独测试,SPI通信基本正确。外部可变的数据输入fpga,通过spi也基本正确,外部输入变化,单片机接收的数据也会相应的变化。测试SRAM时,参考网上的DE2开发板的SRAM例子,往SRAM里写固定的递增数据,然后由输入的拨码开关选择地址,读出相应的数据。这也是正确的,但这只是写入固定的数据,然后,我增加了外部数据输入口,先执行写再执行读,数据正确。改变外部输入数据,再写后,读出,发现还是上一次写的数据。自己调了好些天,也不知道哪里出了错,请各位大侠帮我分析分析,有用过SRAM做过相关操作的,如能给些建议,更加感谢!谢谢大家帮忙!
此帖出自
小平头技术问答
module simple_exram(
input clk,
input wr,
input rd,
input[7:0] adc_data_in,
input[17:0]wr_end_addr,
output MEM_WE_N,
output reg MEM_OE_N,
output[17:0] MEM_A,
inout[7:0] MEM_DATA,
input[17:0] addr_to_read,
output reg[7:0] data_read
);
/*************** extern_ram *****************/
reg[17:0] wr_addr18 = 18'd0;
reg[17:0] rd_addr18 = 18'd0;
//读数据
reg[7:0] Data_out_r = 8'h00;
always @(posedge clk)
begin
if(rd==1'b1)
begin
MEM_OE_N <= 1'b0;
rd_addr18 <= addr_to_read;
Data_out_r <= MEM_DATA;
data_read <= Data_out_r;
end
else
begin
MEM_OE_N <= 1'b1;
rd_addr18 <= 18'd0;
Data_out_r <= 8'h00;
end
end
//写数据
reg flag = 1'b0;
reg we_r = 1'b0;
reg[7:0] bufdata = 8'd0;
reg[17:0] wr_addr18_reg = 18'd0;
always @(posedge clk)
begin
if(wr == 1'b1)
begin
if(wr_addr18 <= wr_end_addr)
begin
if(!flag)
begin
we_r <= 1'b1;
wr_addr18 <= wr_addr18_reg;
wr_addr18_reg <= wr_addr18_reg + 18'd1;
bufdata <= adc_data_in;
flag <= 1'b1;
end
else
begin
we_r <= 1'b0;
wr_addr18 <= wr_addr18;
bufdata <= bufdata;
flag <= 1'b0;
end
end
else
begin
we_r <= 1'b0;
flag <= 1'b0;
wr_addr18 <= wr_addr18;
bufdata <= bufdata;
end
end
else
begin
we_r <= 1'b0;
wr_addr18_reg <=18'd0;
wr_addr18 <= 18'd0;
bufdata <= 8'd0;
flag <= 1'b0;
end
end
assign MEM_A = wr?wr_addr18:rd_addr18;
assign MEM_WE_N = (~we_r)?1'b1:1'b0;
assign MEM_DATA = we_r? bufdata:8'hzz;
endmodule
一周热门 更多>