FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
5988 Discussions

Problem with i2c and fpga

Altera_Forum
Honored Contributor II
1,068 Views

Hi, 

 

I'm using an Altera Cyclone ll as fpga with a nios to communicate with a sfr08 sensor. 

I downloaded the opencore IP found in the wiki but i have a problem with it. 

I integrated it in the SOPC builder and generated the processor without problem, also the bdf file compiles without errors. 

I read the documentation but i'm not able to communicate with the internal registers of the module, probably due to a wrong memory address. 

Here is the code i'm using: 

 

//the i2c module in the sopc has the address 0x00101000; volatile int * red_LED_ptr = (int *) 0x00101040; // red LED address int * Control = (int *) 0x00101002; int * Send = (int *) 0x00101003; int * Command = (int *) 0x00101004; volatile int * Receive = (int *)0x00101003; volatile int * Status = (int *)0x00101004; int main(void) { int stato; *(Control) = 0x80; //enable the i2c core * (Command) = 0x90; //set STA bit and WR bit * (Send) = 0xa0; //device address with last bit 0 (write) do{ stato = * (Status);} //check status register for the TIP bit while ((stato & 0x02 )!= 0x00); // TIP == 0 --> trasimssion complete if ((stato & 0x80) == 0x00){ // if ack send register address * (Send) = 0x00; // register address * (Command) = 0x10; //set STA bit and WR bit } do{ stato = * (Status);} // TIP control as before while ((stato & 0x02 )!= 0x00) ; if ((stato & 0x80) == 0x00){ //if ack send data * (Send) = 0x51; //data to write * (Command) = 0x50; //set STA bit and WR bit } do{ stato = * (Status);} // TIP control as before while ((stato & 0x02 )!= 0x00) ; *(red_LED_ptr)= stato; // put the status register (with ack bit) on led } Any suggestion will be appreciate, thanks
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
82 Views

You don't need to set pointers to component addresses. Those addresses are defined in system.h file, so use them instead. Check the core examples, they're very informative.

Altera_Forum
Honored Contributor II
82 Views

Thanks for the suggestion, i should think to it by myself. 

 

Even if i can't find the file system.h i was able compile the code without it and now it works. 

 

Thanks again.
Altera_Forum
Honored Contributor II
82 Views

It's in the BSP directory.

Reply