i2c in xem 3005


Im using the xem 3005 board to control a microcontroller (pic16F874, by Microchip). Im very glad to know that there’re i2c read and write functions and tested them. However, I always get a “Nack” error when i try to write the mcu - the address is sent but not the data. Testing the mcu i2c using two mcu’s, i see that clock signal (SCL) is about 30khz (fpga’s SCL clock is about 300khz) and the i2c link works fine.
I dont think it’s a frequency problem because 16F874 supports SCL up to 400khz.
So, i have a few questions, please:

  1. Do I need to load some .bit file in fpga before using the i2c? Im asking because I dont load anything and it still sends the i2c signal through the pins. I’m concerned that if I dont load anything, the SCL ans SDA pins ‘high z’ constraints will not work, making the fpga blind to any Acknowlege signal from mcu.

  2. I’m using Matlab (on dll available) and the data parameter type is unsigned char. The matlab uint8 type work well? (ex: data= uint8([1 1 0 0 1 0 1 0]), for only one byte to send.

Thank you very much,


@joao- The FPGA is not the I2C master. The USB microcontroller is.

Generally, we recommend programming an I2C master into the FPGA fabric and using that. It will be more flexible than use the I2C interface we provide over the FrontPanel API.

One thing to watch out for is that the I2C protocol specifies a 7-bit address. But some documents describe it as an 8-bit address where there are separate read/write addresses.

Our API only takes the 7-bit address and automatically assigns the “8th bit” for reads and writes.


Any idea where to get a i2c in vhdl or verilog, please? Thanks again


I entered “i2c verilog” into Google and clicked “I’m feeling lucky” I got this link that includes source and a test bench:


OpenCores also has an I2C block, but it interfaces to WISHBONE which probably makes it more complicated than it needs to be. The source should still be helpful.

I2C is a pretty simple protocol, though. A simple state machine can handle the entire thing. It’s basically a shift register with a little control logic.