here's a basic i2c example, I think it will work the DE2's codec
/////////////////////////////////////////////////////
//
// Wolfson WM8731 Audio Codec Interface (I2C)
//
// marshallh, Feb 14, 2012
//
// Implements the I2C interface for configuration.
//
//////////////////////////////////////////////////////
module audio_i2c
(
clk,
ar,
addr,
wr,
data,
strobe,
busy,
i2c_sclk,
i2c_sdat_out,
i2c_sdat_oe,
);
input wire clk;
input wire ar;
output reg i2c_sclk;
output reg i2c_sdat_out;
output reg i2c_sdat_oe;
input wire [6:0] addr;
input wire wr;
input wire [8:0] data;
input wire strobe;
reg strobe_1;
reg [2:0] state;
reg [28:0] shift;
reg [28:0] shift_oe;
reg [6:0] clk_cnt;
reg [6:0] cnt;
output reg busy;
always @(posedge clk or negedge ar) begin
if(~ar) begin
// reset state
state <= 0;
i2c_sdat_oe <= 0;
i2c_sdat_out <= 1;
i2c_sclk <= 1;
busy <= 1;
end else begin
// normal operation
strobe_1 <= strobe;
case(state)
0: begin
busy <= 0;
i2c_sclk <= 1;
if(strobe & ~strobe_1) begin
// rising edge of strobe
shift <= {1'b0, 7'b0011010, ~wr, 1'b0, addr, data[8], 1'b0, data[7:0], 2'b0};
shift_oe <= 29'b11111111101111111101111111100;
state <= 1;
busy <= 1;
end
clk_cnt <= 0;
cnt <= 0;
end
1: begin
cnt <= cnt + 1;
i2c_sdat_out <= 1;
i2c_sdat_oe <= 1;
if(cnt == 31) begin
cnt <= 0;
state <= 2;
end
end
2: begin
// assert SDAT before starting clock
i2c_sdat_out <= 0;
cnt <= cnt + 1;
if(cnt == 31) begin
cnt <= 0;
state <= 3;
end
end
3: begin
// shift out the entire packet
i2c_sdat_oe <= shift_oe[28];
i2c_sdat_out <= shift[28];
clk_cnt <= clk_cnt + 1;
if(clk_cnt == 127) begin
// toggle clk
i2c_sclk <= ~i2c_sclk;
if(cnt == 28) begin
// done
state <= 4;
i2c_sclk <= 1;
//i2c_sdat_out <= 0;
end
end
if(clk_cnt == 64 && ~i2c_sclk) begin
// do shift
shift <= {shift[27:0], 1'b0};
shift_oe <= {shift_oe[27:0], 1'b0};
cnt <= cnt + 1;
end
end
4: begin
cnt <= cnt + 1;
if(cnt == 64) i2c_sdat_out <= 1;
if(cnt == 127) state <= 5;
end
5: begin
// return to idle state
i2c_sclk <= 1;
//i2c_sdat_oe <= 0;
state <= 0;
end
endcase
end
end
endmodule