main
lincaigui 7 months ago
parent d299e2cb77
commit 940257ecb7

Binary file not shown.

Binary file not shown.

@ -38,11 +38,12 @@ reg [4: 0] cnt_clk;
//
reg [9: 0] cnt_wait ;//1000us
reg skip_en_1 ;//1
reg skip_en_2 ;//2
reg skip_en_3 ;//3
reg skip_en_4 ;//4
reg skip_en_5 ;//5
reg skip_en_1 ;//1,
reg skip_en_2 ;//2,bank0
reg skip_en_3 ;//3,0x00
reg skip_en_4 ;//4,0x20
reg skip_en_5 ;//5,51
reg skip_en_6 ;//6,0x43
reg [1: 0] cnt_i2c_clk ;//i2c
reg [2: 0] cnt_bit ;//bit
reg i2c_end ;//i2c
@ -106,13 +107,13 @@ end
//
always @(*)begin
case(state_c)
IDLE: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1))begin
IDLE: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = START;
end
else begin
state_n = IDLE;
end
START: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1))begin
START: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = SLAVE_ADDR;
end
else begin
@ -121,13 +122,13 @@ always @(*)begin
SLAVE_ADDR: if(skip_en_1 == 1'b1)begin
state_n = WAIT;
end
else if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1))begin
else if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = ACK_1;
end
else begin
state_n = SLAVE_ADDR;
end
ACK_1: if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_5 == 1'b1))begin
ACK_1: if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = DEVICE_ADDR;
end
else if(skip_en_4 == 1'b1)begin
@ -136,7 +137,7 @@ always @(*)begin
else begin
state_n = ACK_1;
end
DEVICE_ADDR:if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_5 == 1'b1))begin
DEVICE_ADDR:if((skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = ACK_2;
end
else begin
@ -145,7 +146,7 @@ always @(*)begin
ACK_2: if((skip_en_2 == 1'b1) || (skip_en_5 == 1'b1))begin
state_n = DATA;
end
else if(skip_en_3 == 1'b1)begin
else if((skip_en_3 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = STOP;
end
else begin
@ -181,7 +182,7 @@ always @(*)begin
else begin
state_n = WAIT;
end
STOP: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1))begin
STOP: if((skip_en_1 == 1'b1) || (skip_en_2 == 1'b1) || (skip_en_3 == 1'b1) || (skip_en_4 == 1'b1) || (skip_en_5 == 1'b1) || (skip_en_6 == 1'b1))begin
state_n = IDLE;
end
else begin
@ -201,6 +202,7 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
skip_en_3 <= 1'b0;//3
skip_en_4 <= 1'b0;//4
skip_en_5 <= 1'b0;//5
skip_en_6 <= 1'b0;//6
step <= 3'd0;
err_en <= 1'b0;
cnt_i2c_clk <= 2'd0;
@ -245,7 +247,13 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
end
else begin
skip_en_5 <= 1'b0;
end
if((cnt_wait == MAX - 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
end
START: begin
cnt_i2c_clk <= cnt_i2c_clk + 1'd1;
@ -279,6 +287,12 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
end
SLAVE_ADDR: begin
cnt_i2c_clk <= cnt_i2c_clk + 1'd1;
@ -312,6 +326,12 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd5) && (cnt_bit == 3'd7))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
if((cnt_bit == 3'd7) && (cnt_i2c_clk == 2'd3))begin
cnt_bit <= 3'd0;
end
@ -348,6 +368,12 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
else begin
skip_en_5 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
end
DEVICE_ADDR:begin
cnt_i2c_clk <= cnt_i2c_clk + 1'b1;
@ -378,6 +404,12 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (cnt_bit == 3'd7) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
end
ACK_2: begin
cnt_i2c_clk <= cnt_i2c_clk + 1;
@ -399,6 +431,12 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
else begin
skip_en_5 <= 1'b0;
end
if((ack == 1'b1) && (cnt_i2c_clk == 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
end
DATA: begin
cnt_i2c_clk <= cnt_i2c_clk + 1'b1;
@ -512,13 +550,19 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
else begin
skip_en_5 <= 1'b0;
end
if((cnt_i2c_clk == 2'd2) && (step == 3'd5))begin
skip_en_6 <= 1'b1;
end
else begin
skip_en_6 <= 1'b0;
end
if(cnt_i2c_clk == 2'd2)begin
i2c_end <= 1'b1;
end
else begin
i2c_end <= 1'b0;
end
if((i2c_end == 1'b1) && (step <= 3'd3))begin
if((i2c_end == 1'b1) && ((step <= 3'd3) || step == 3'd5))begin
step <= step + 1'd1;
end
else if((i2c_end == 1'b1) && (step == 3'd4) && (cfg_num == 6'd51))begin
@ -535,6 +579,7 @@ always @(posedge i2c_clk or negedge sys_rst_n)begin
skip_en_3 <= 1'b0;
skip_en_4 <= 1'b0;
skip_en_5 <= 1'b0;
skip_en_6 <= 1'b0;
err_en <= 1'b0;
step <= step;
cnt_i2c_clk <= 2'd0;
@ -599,6 +644,11 @@ always @(*)begin
device_addr= cfg_data[15: 8];
wr_data = cfg_data[7: 0];
end
3'd5: begin
slave_addr = {SLAVE_ID, 1'b0};//
device_addr= 8'h43;
wr_data = 8'h00;
end
default:begin
slave_addr = 8'h0;
device_addr = 8'h0;

Loading…
Cancel
Save