initial begin
cs = 1;
MOSI = 0;
sclk = 0;
done = 0;
count = 0;
temp_data =32'b00000000000000000000000000000000;
bit_count = 0;
state = 0;
count2 = 0;
end
// clock dividwer
always @(posedge sys_clk)
begin
if (count == 4)
begin
sclk <= ~sclk;
count <= 11'b00000000000;
end
else
begin
count = count +1;
end
end
// functional design
always @(posedge sclk)
begin
case (state)
idle :
begin
done = 1'b0;
cs = 1'b1;
state = data_tx;
temp_data[7:0] = 8'b00000000;
temp_data[19:8] = count2;
temp_data[31:20] = 12'b100000001111;
MOSI = 0;
count2 = count2 + 1;
end
data_tx:
begin
cs = 1'b0;
MOSI = temp_data[31-bit_count];
if (bit_count == 32)
begin
state = finish;
bit_count = 0;
done = 1'b1;
MOSI = 0;
end
else
begin
bit_count = bit_count + 1;
end
end
finish:
begin
cs = 1'b1;
state = idle;
MOSI = 0;
end
Question
Gopal Krishna
I am trying to interface PMOD DA4 with atlys FPGA but nothing is coming at output. help me to rectify what wrong with code.
module spi_master_v1(
input sys_clk,
input rst,
output reg cs,
output reg MOSI,
output reg sclk,
// input [31:0] in_data,
output reg done
);
// Internal registers
reg [10:0] count;
reg [31:0] temp_data;
reg [5:0] bit_count;
reg [11:0] count2;
// state declearation
reg [1:0] state;
parameter idle = 2'b00;
parameter data_tx = 2'b01;
parameter finish = 2'b10;
//initialize all register
initial begin
cs = 1;
MOSI = 0;
sclk = 0;
done = 0;
count = 0;
temp_data =32'b00000000000000000000000000000000;
bit_count = 0;
state = 0;
count2 = 0;
end
// clock dividwer
always @(posedge sys_clk)
begin
if (count == 4)
begin
sclk <= ~sclk;
count <= 11'b00000000000;
end
else
begin
count = count +1;
end
end
// functional design
always @(posedge sclk)
begin
case (state)
idle :
begin
done = 1'b0;
cs = 1'b1;
state = data_tx;
temp_data[7:0] = 8'b00000000;
temp_data[19:8] = count2;
temp_data[31:20] = 12'b100000001111;
MOSI = 0;
count2 = count2 + 1;
end
data_tx:
begin
cs = 1'b0;
MOSI = temp_data[31-bit_count];
if (bit_count == 32)
begin
state = finish;
bit_count = 0;
done = 1'b1;
MOSI = 0;
end
else
begin
bit_count = bit_count + 1;
end
end
finish:
begin
cs = 1'b1;
state = idle;
MOSI = 0;
end
endcase
end
endmodule
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.