Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
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.
12434 Discussions

How to do read operation using opencore i2c ip drivers?

Honored Contributor II

In my design, I use opencore i2c ip for my i2c interface. This core provides the drivers which includes I2C_init, I2C_start, I2C_read, I2C_write.  


The writing operation is straightforward but sometimes i2c reading operation is confused. In this case, the I2C_read function is : 




int I2C_read 

assumes that any addressing and start 

has already been done. 

reads one byte of data from the slave. on the last read 

we don't acknowldge and set the stop bit. 


base = the base address of the component 

last = on the last read there must not be a ack 



return value 

byte read back. 

15-OCT-07 initial release 


alt_u32 I2C_read(alt_u32 base,alt_u32 last) 



so this read function doesn't have an argument for the i2c slave address. So my understanding is I need a writing operation before read to write to the i2c slave for the initial inner address. Since before the read or write, it requests a start, what I think the general procedure is : 


i2c_start(); // configure for write 

i2c_write(base, slave_inner_address, last); 

i2c_start(); // configure for read 




Currently I don't have a hardware for testing, if anyone has experience about opencore i2c ip driver, I would appreciate if you can have a look to see whether my understanding about reading operation is correct. 


Thanks in advance.
0 Kudos
2 Replies
Honored Contributor II

Your understanding of the general procedure is correct. 


Docs/i2c_test.c gives some examples.
Honored Contributor II


--- Quote Start ---  

Your understanding of the general procedure is correct. 


Docs/i2c_test.c gives some examples. 

--- Quote End ---  



Hi ted, I ignored the i2c_test.c in Docs folder, now I checked it. Thanks so much!