FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
6343 Discussions

I2C (OpenCores) not working

TFern4
Novice
1,886 Views

Hi, I am using the I2C OpenCores v13.0 from https://fpgawiki.intel.com/wiki/I2C_(OpenCores) with the Platform Designer/Qsys and the Nios II Processor on the Quartus Prime, but it isn't working. I don't know what steps I may have done wrong. First I unzip the .zip and added the path of the files to generate the I2C component in Qsys. So in the _sw.tcl file I've changed the "opencores_i2c" by "i2c_opencores" beacuse the _hw.tcl and _sw.tcl name weren't in agreement (https://forums.intel.com/s/question/0D50P00003yyRELSA2/how-to-use-i2copencoresswtcl-in-i2c-opencores). After that I made the C code in Eclipse, as follow:

 

#include <stdio.h>

#include "system.h"

#include "i2c_opencores.h"

 

int main(){

  int data;

 // address to communicate 0x08 

// Frequency 100 kHz 

I2C_init(I2C_BASE,ALT_CPU_FREQ,100000);

 

while(1){

I2C_start(I2C_BASE,0x08,1); // chip address in read mode

data = I2C_read(I2C_BASE,1); // read the input register and send stop

printf("data = %d\n",data);

}

return 0;

}

 

The code compiles without errors or warnings, all the drivers and libraries (i2c_opencores.c, i2c_opencores.h, i2c_opencores_regs.h) were linked to Eclipse automatically. In the Nios console I see nothing, any value received. I also verified the SDA and SCL lines in an oscilloscope, but no signal. If someone can help me, I appreciate it. Below I've attached the configuration in Qsys. Thanks in advance. Untitled.jpg

0 Kudos
7 Replies
Fawaz_Al-Jubori
Employee
1,044 Views

Hello,

I am sending you a working design of Cyclone V soc using Opencores I2C. The I2C was used to read data from a sensor. I was able to see the sensor data output as expected without any issue.

Attached is the design.

 

Best Regards.

 

0 Kudos
TFern4
Novice
1,044 Views

Do you know if using only the Nios II, without the HPS will it work? How did you make to run the C program with the I2C functions in Eclipse? I didn't find the .sopcinfo in your design . Thank you.

0 Kudos
TFern4
Novice
1,044 Views

Do you know if using only the Nios II, without the HPS will it work? How did you make to run the C program with the I2C functions in Eclipse? I didn't find the .sopcinfo in your design . Thank you.

0 Kudos
Fawaz_Al-Jubori
Employee
1,044 Views

Hello,

You have the Qsys file, so you can generate the sopcinfo from it easy. After generating the Qsys file, you will get the sopcinfo file. Use this file to create your hello world project.

 

Yes sure, you can use Nios II only. This was one of my designs which combines Nios II and HPS. I am attaching a simpler version of qsys file.

 

0 Kudos
Fawaz_Al-Jubori
Employee
1,044 Views
0 Kudos
TFern4
Novice
1,044 Views

Hello,

I tried to do my design again based on your Qsys file and it did not work. I put the SCL and SDA on an oscilloscope, but the output was just noise, nor the clock in the SCL was generated. In Qsys, I added the OpenCores I2C component in Tools > Options > IP Search Path, is this correct? Do I need to do anything else? Because the other settings and procedures are the same as your design. Thank you so much for helping me.

Fawaz_Al-Jubori
Employee
1,044 Views
Hello, Have you tried the C code available with in the attachment? I have verified this design at my side, and It works perfectly. Thanks
0 Kudos
Reply