Index: trunk/MultiChannelUSB/Paella.qsf
===================================================================
--- trunk/MultiChannelUSB/Paella.qsf	(revision 68)
+++ trunk/MultiChannelUSB/Paella.qsf	(revision 69)
@@ -59,4 +59,5 @@
 set_global_assignment -name VERILOG_FILE oscilloscope.v
 set_global_assignment -name VERILOG_FILE usb_fifo.v
+set_global_assignment -name VERILOG_FILE i2c_fifo.v
 set_global_assignment -name VERILOG_FILE uwt_bior31.v
 set_global_assignment -name VERILOG_FILE test.v
@@ -110,11 +111,11 @@
 set_location_assignment PIN_70 -to USB_PB[2]
 set_location_assignment PIN_71 -to USB_PB[3]
-set_location_assignment PIN_72 -to CON_A[0]
-set_location_assignment PIN_73 -to CON_A[1]
-set_location_assignment PIN_76 -to CON_A[2]
-set_location_assignment PIN_78 -to CON_A[3]
-set_location_assignment PIN_80 -to CON_A[4]
-set_location_assignment PIN_81 -to CON_A[5]
-set_location_assignment PIN_82 -to CON_A[6]
+set_location_assignment PIN_72 -to I2C_SDA
+set_location_assignment PIN_73 -to I2C_SCL
+set_location_assignment PIN_76 -to CON_A[0]
+set_location_assignment PIN_78 -to CON_A[1]
+set_location_assignment PIN_80 -to CON_A[2]
+set_location_assignment PIN_81 -to CON_A[3]
+set_location_assignment PIN_82 -to CON_A[4]
 set_location_assignment PIN_83 -to TRG[0]
 set_location_assignment PIN_84 -to TRG[1]
@@ -234,4 +235,6 @@
 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_SLWR
 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_IFCLK
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to I2C_SDA
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to I2C_SCL
 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_A[0]
 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_A[1]
@@ -239,6 +242,4 @@
 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_A[3]
 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_A[4]
-set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_A[5]
-set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_A[6]
 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to TRG[0]
 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to TRG[1]
Index: trunk/MultiChannelUSB/control.v
===================================================================
--- trunk/MultiChannelUSB/control.v	(revision 68)
+++ trunk/MultiChannelUSB/control.v	(revision 69)
@@ -4,4 +4,5 @@
 		input	wire			rx_empty, tx_full,
 		input	wire	[7:0]	rx_data,
+
 		input	wire	[1:0]	mux_max_byte,
 		input	wire	[15:0]	mux_min_addr, mux_max_addr,
@@ -13,10 +14,17 @@
 		output	wire	[1:0]	mux_byte,
 		output	wire	[15:0]	mux_addr,
+
 		output	wire			rx_rdreq,
 		output	wire			tx_wrreq,
 		output	wire	[7:0]	tx_data,
+
 		output	wire			ram_we,
 		output	wire	[19:0]	ram_addr,
 		inout	wire	[17:0]	ram_data,
+
+		output	wire			i2c_wrreq,
+		output	wire	[15:0]	i2c_data,
+		input	wire			i2c_full,
+
 		output	wire			led
 	);
@@ -33,4 +41,7 @@
 	reg				int_led;
 
+	reg 	[15:0]	int_i2c_data;
+	reg 			int_i2c_wrreq;
+
 
 	wire			crc_error = 1'b0;
@@ -39,5 +50,5 @@
 	reg		[4:0]	idle_counter;
 
-	reg		[3:0]	state;
+	reg		[4:0]	state;
 	
 	wire	[15:0]	src, dst;
@@ -56,5 +67,6 @@
 	assign	int_ram_q = ram_data;
 //	assign	ram_data = int_ram_we ? int_ram_data : 18'bz;
-	assign	ram_addr = {ram_counter[18:5],1'd0,ram_counter[4:0]};
+//	assign	ram_addr = {ram_counter[18:5],1'd0,ram_counter[4:0]};
+	assign	ram_addr = {1'd0, ram_counter[18:0]};
 
 	genvar j;
@@ -101,5 +113,5 @@
 				idle_counter <= 5'd0;
 				byte_counter <= 3'd0;
-				state <= 4'd1;
+				state <= 5'd1;
 			end
 
@@ -115,5 +127,5 @@
 					begin
 						int_rdreq <= 1'b0;
-						state <= 4'd2;
+						state <= 5'd2;
 					end
 				end
@@ -125,5 +137,5 @@
 						int_rdreq <= 1'b0;
 						crc_reset <= 1'b1;
-						state <= 4'd0;
+						state <= 5'd0;
 					end
 				end
@@ -140,5 +152,5 @@
 						16'h0000:
 						begin
-							state <= 4'd0;
+							state <= 5'd0;
 						end
 
@@ -148,5 +160,5 @@
 							int_chan <= src[1:0];
 							int_reset <= 1'b1;
-							state <= 4'd0;
+							state <= 5'd0;
 						end
 
@@ -155,5 +167,5 @@
 							int_type <= src[4];
 							int_chan <= src[1:0];
-							state <= 4'd3;
+							state <= 5'd3;
 						end
 
@@ -161,5 +173,5 @@
 						begin
 							tst_counter <= 11'd0;	
-							state <= 4'd6;
+							state <= 5'd6;
 						end
 						16'h0004:
@@ -168,5 +180,11 @@
 							int_ram_data <= 18'd0;
 							ram_counter <= 19'd0;	
-							state <= 4'd9;
+							state <= 5'd9;
+						end
+						16'h0005:
+						begin
+							int_i2c_data <= src;
+							int_i2c_wrreq <= 1'b1;
+							state <= 5'd15;
 						end
 					endcase
@@ -182,5 +200,5 @@
 				int_max_byte <= mux_max_byte;
 				int_byte <= 2'd0;	
-				state <= 4'd4;
+				state <= 5'd4;
 			end
 	
@@ -188,5 +206,5 @@
 			begin
 				int_wrreq <= 1'b0;
-				state <= 4'd5;
+				state <= 5'd5;
 			end
 
@@ -199,9 +217,9 @@
 					if ((int_byte == int_max_byte) && (int_addr == int_max_addr))
 					begin
-						state <= 4'd0;
+						state <= 5'd0;
 					end
 					else
 					begin
-						state <= 4'd4;
+						state <= 5'd4;
 						if (int_byte == int_max_byte)
 						begin
@@ -224,5 +242,5 @@
 				int_wrreq <= 1'b1;
 				tst_counter <= tst_counter + 11'd1;
-				state <= 4'd7;
+				state <= 5'd7;
 			end
 			7:
@@ -233,5 +251,5 @@
 					if (&tst_counter)
 					begin
-						state <= 4'd8;
+						state <= 5'd8;
 					end
 					else
@@ -246,5 +264,5 @@
 				begin
 					int_wrreq <= 1'b0;
-					state <= 4'd0;
+					state <= 5'd0;
 				end
 			end
@@ -253,5 +271,5 @@
 			begin
 				crc_reset <= 1'b0;
-				state <= 4'd10;
+				state <= 5'd10;
 			end
 			10:
@@ -261,9 +279,9 @@
 				if (&ram_counter)
 				begin
-					state <= 4'd11;
+					state <= 5'd11;
 				end
 				else
 				begin
-					state <= 4'd9;
+					state <= 5'd9;
 					ram_counter <= ram_counter + 19'd1;
 				end
@@ -274,14 +292,14 @@
 				int_ram_data <= 18'd0;
 				ram_counter <= 19'd0;
-				state <= 4'd12;
+				state <= 5'd12;
 			end
 			12:
 			begin
 				int_wrreq <= 1'b0;
-				state <= 4'd13;
+				state <= 5'd13;
 			end
 			13:
 			begin
-				state <= 4'd14;
+				state <= 5'd14;
 			end
 			14:
@@ -293,9 +311,9 @@
 					if (&ram_counter)
 					begin
-						state <= 4'd0;
+						state <= 5'd0;
 					end
 					else
 					begin
-						state <= 4'd12;
+						state <= 5'd12;
 						ram_counter <= ram_counter + 19'd1;
 					end
@@ -303,7 +321,18 @@
 			end
 						
+			// i2c write
+			15:
+			begin
+				crc_reset <= 1'b0;
+				if (~i2c_full)
+				begin
+					int_i2c_wrreq <= 1'b0;
+					state <= 5'd0;
+				end
+			end
+
 			default:
 			begin
-				state <= 4'd0;
+				state <= 5'd0;
 			end
 		endcase
@@ -318,4 +347,6 @@
 	assign	tx_wrreq = int_wrreq & (~tx_full);
 	assign	tx_data = int_data;
+	assign	i2c_wrreq = int_i2c_wrreq;
+	assign	i2c_data = int_i2c_data;
 	assign	led = int_led;
 
