Altera_Forum
Honored Contributor
9 years agoReading/Writing from/to 16 Mbit Flash RAM (S29AL016M10TAI020)
Hi, I am trying to interact with a 16 Mbit Flash RAM (S29AL016M10TAI020) in Verilog, but I have some problems. This flash supports byte or word mode,
I have studied the datasheet and I have tried to implement a flash controller in byte mode. Question: is it necessary to do the Word/Byte Program Command Sequence first (a four cycle operation)? Also, what is the Program Address and the Program Data that I must specify (4th clock cycle of command sequence)? Also i need some help with the code. I want to read data from the flash so i execute the Word/Byte Program Command Sequence first and then start reading. Am i doing sth wrong?
module flash_controller(clock, reset_n, mem_mode, mem_ce_n, mem_rst_n, mem_oe_n, mem_we_n, address, data, flash_data);
// Controller inputs: clock of 10Mhz and negedge reset
input clock, reset_n;
// Flash Signals
output mem_mode, mem_ce_n, mem_rst_n, mem_oe_n, mem_we_n; // in flash they are inputs
output address; // in flash it is input
inout data; // in flash it is inout
// Controller output to check the read data
output flash_data;
wire nclock;
reg cycles;
reg write_data;
reg read_data;
reg mem_rst_n, mem_oe_n, mem_we_n;
reg address;
assign mem_mode = 1'b0; // to select byte mode
assign mem_ce_n = 1'b0; // always at 0 so the chip is enabled
// if mem_oe_n == H then write data else Z
assign data = (mem_oe_n) ? write_data : 8'bZ;
assign flash_data = read_data;
// ADDRESSES are latched on the NEGEDGE of mem_we_n
// DATA are latched on the POSEDGE of mem_we_n
assign nclock = !clock;
// clock cycles 1-4: flash programming at byte mode (is it necessary??):
// cc1: write AA at AAA
// cc2: write 55 at 555
// cc3: write A0 at AAA
// cc4: write Program Data at Program Address (whats this?)
// clock cycles >= 5: flash reading and showing the data at the output via flash data
always @ (posedge clock or posedge nclock or negedge reset_n)
begin
if (!reset_n) // RESET
begin
cycles = 3'd0;
mem_rst_n = 1'b0;
address = 21'd0;
end
else if (clock) // CLOCK POSEDGE
begin
if (cycles < 3'd4) // clock cycles 1-4: flash programming
begin
mem_we_n = 1'b0; // do the negedge of mem_we_n to latch the address
mem_oe_n = 1'b1; // output disable
mem_rst_n = 1'b1; // no reset
case (cycles)
3'd0: begin
address = 21'b000000000101010101010; // AAA
write_data = 8'b10101010; // AA
end
3'd1: begin
address = 21'b000000000010101010101; // 555
write_data = 8'b01010101; // 55
end
3'd2: begin
address = 21'b000000000101010101010; // AAA
write_data = 8'b10100000; // A0
end
3'd3: begin
address = 21'd0; // ??? what should I put here, it says the program address
write_data = 8'd10; // ??? what should I put here, it says the program data
end
endcase
cycles = cycles + 1;
end
else // clock cycles >= 5: flash reading
begin
mem_we_n = 1'b0; // do the negedge of mem_we_n to latch the address
mem_oe_n = 1'b0; // output enable
address = address + 1;
read_data = data;
end
end
else // CLOCK NEGEDGE
begin
mem_we_n = 1'b1; // do the posedge of mem_we_n to latch the data (write or read)
end
end
endmodule
Thanks very much in advance. Any help is appreciated :)