module my_simpleI2C_rw_v2 (clk, address, readdata, writedata, read, write, reset_n,sda,scl); parameter ADDRSIZE = 2; parameter WORDSIZE = 32; parameter FREQDIV =2; input clk; input [ADDRSIZE-1:0] address; output reg [WORDSIZE-1:0] readdata; input [WORDSIZE-1:0] writedata; input read,write; input reset_n; inout sda,scl; reg [WORDSIZE-1:0] Mem [0:(1<39)) begin cmd_sda=4'b1111; cmd_scl=4'b1111; end else if ((counter_bit>29)&&(w_nr)) begin cmd_sda=4'b1111; cmd_scl=4'b1111; end else if (w_nr) begin case ({bits_to_write[counter_bit-1],ctrl_to_write[counter_bit-1]}) 2'b01: begin cmd_sda=4'b1000; cmd_scl=4'b1110; end 2'b11: begin cmd_sda=4'b0001; cmd_scl=4'b0111; end 2'b00: begin cmd_sda=4'b0000; cmd_scl=4'b0110; end 2'b10: begin cmd_sda=4'b1111; cmd_scl=4'b0110; end default: begin cmd_sda=4'b1111; cmd_scl=4'b1111; end endcase end else case ({bits_to_read[counter_bit-1],ctrl_to_read[counter_bit-1]}) 2'b01: begin cmd_sda=4'b1000; cmd_scl=4'b1110; end 2'b11: begin cmd_sda=4'b0001; cmd_scl=4'b0111; end 2'b00: begin cmd_sda=4'b0000; cmd_scl=4'b0110; end 2'b10: begin cmd_sda=4'b1111; cmd_scl=4'b0110; end default: begin cmd_sda=4'b1111; cmd_scl=4'b1111; end endcase sda_o=cmd_sda[counter_4]; scl_o=cmd_scl[counter_4]; end end always @(posedge clk) begin if (counter_reg==80) ack1=sda; if (counter_reg==44) ack2=sda; if (w_nr) begin if (counter_reg==8) ack3=sda; end else begin if (counter_reg==12) ack3=sda; if ((counter_4==3) && (counter_bit>=3)&&(counter_bit<=10)) out_bits[counter_bit-3]<=sda; end end always @(posedge clk) if (counter_reg==8'b0) begin Mem[1] = out_bits; Mem[2] = {29'h0,ack1,ack2,ack3}; end endmodule