Skip to content

Commit

Permalink
reading works but kills codec somehow
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Oct 23, 2023
1 parent 6e9ae2b commit 784cf77
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions gateware/drivers/pmod_i2c_master.sv
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ localparam I2C_DELAY1 = 0,
I2C_INIT_TOUCH2 = 6,
I2C_INIT_TOUCH3 = 7,
I2C_INIT_TOUCH4 = 8,
I2C_LED1 = 9, // <<--\ LED/JACK re-runs indefinitely.
I2C_LED1 = 9, // <<--\ LED/JACK/TOUCH re-runs indefinitely.
I2C_LED2 = 10, // |
I2C_JACK1 = 11, // |
I2C_JACK2 = 12, // >>--/
I2C_IDLE = 13;
I2C_JACK2 = 12, // |
I2C_TOUCH5 = 13, // |
I2C_TOUCH6 = 14, // >>--/
I2C_IDLE = 15;


logic [3:0] i2c_state = I2C_DELAY1;
Expand Down Expand Up @@ -399,9 +401,9 @@ always_ff @(posedge clk) begin

// 4) Save the result.
10: begin
jack <= data_out;
//jack <= data_out;
cmd <= I2CMASTER_STOP;
i2c_state <= I2C_LED1;
i2c_state <= I2C_TOUCH5;
delay_cnt <= 0;
end
default: begin
Expand All @@ -412,6 +414,41 @@ always_ff @(posedge clk) begin
ack_in <= 1'b1;
stb <= 1'b1;
end
I2C_TOUCH5: begin
i2c_state <= I2C_TOUCH6;
i2c_config_pos <= 0;
end
I2C_TOUCH6: begin
case (i2c_config_pos)
// Set slave read pointer
0: cmd <= I2CMASTER_START;
1: begin
data_in <= 8'h6E;
cmd <= I2CMASTER_WRITE;
end
2: data_in <= 8'hAA;
3: cmd <= I2CMASTER_STOP;

// Read out the data
4: cmd <= I2CMASTER_START;
5: begin
data_in <= 8'h6F;
cmd <= I2CMASTER_WRITE;
end
6: begin
cmd <= I2CMASTER_READ;
end
default: begin
// do nothing
jack <= data_out;
cmd <= I2CMASTER_STOP;
i2c_state <= I2C_LED1;
end
endcase
i2c_config_pos <= i2c_config_pos + 1;
ack_in <= 1'b1;
stb <= 1'b1;
end
default: begin
i2c_state <= I2C_IDLE;
end
Expand Down

0 comments on commit 784cf77

Please sign in to comment.