Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12589 Discussions

How to do read operation using opencore i2c ip drivers?

Altera_Forum
Honored Contributor II
1,171 Views

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. 

inputs 

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 

i2c_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
Altera_Forum
Honored Contributor II
399 Views

Your understanding of the general procedure is correct. 

 

Docs/i2c_test.c gives some examples.
0 Kudos
Altera_Forum
Honored Contributor II
399 Views

 

--- 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!
0 Kudos
Reply