Forum Discussion
I2C interface on Linux (with MMU)
I have a few questions about I2C interfaces on Nios II on Linux with MMU.
I found this thread http://www.alteraforum.com/forum/showthread.php?t=18441 (though forum search for "i2c" or "I2C" doesn't find it). It is a bit fragmented, and difficult to follow. I have a Microtronix i2c interface. Should the OpenCores drivers work with this? I defined I2C_0_BASE, I2C_0_IRQ based on my custom_fpga.h I2C_0_FREQ is being a bit trickier. I assumed it should be the i2c bus speed; however, I discovered that it seems to hang the system at boot if I don't define it as the system clock speed (85 MHz for me).15 Replies
- Altera_Forum
Honored Contributor
Do you need I²C Master or Slave ?
AFAIK, there is a (not bit banging) open core I²C design. I'm not sure if same is already available for the Avalon bus and if there is a current Kernel driver in place. Do you think the Microtronix design offer advantages ? -Michael - Altera_Forum
Honored Contributor
I need the I2C to talk to an RTC chip, an M41T0.
I assume that means the I2C on the FPGA is the master, and the RTC is the slave. I have no idea if the Microtronix design has advantages over the OpenCores design. It is what the hardware guys put in the design. - Altera_Forum
Honored Contributor
With the RTC chip, of course the NIOS is the I²C Master.
For accessing just an RTC Chip, a bit banging I²C driver (no I²C-specific hardware) should work fine. Such a driver is standard in the Linux distribution. If the hardware guys decided to use a piece of hardware they of course will be able to tell you where to find the appropriate (and not outdated) driver. Microtronix usually do provide Linux drivers for their IP Cores. -Michael - Altera_Forum
Honored Contributor
You will need to check the hardware. The hardware decides which driver to use.
I guess the microtronix one is opencore i2c. You have to make sure the component names match the config.c. The m41t00 uses the ds1307 driver. You will need to make sure the i2c address matches the config.c. Please refer to the wiki, http://www.nioswiki.com/operatingsystems/uclinux/video - Hippo - Altera_Forum
Honored Contributor
I've mapped the I2C component name from custom_fpga.h to the one used in config.c., with# defines in nios.h.
My custom_fpga.h does not have a frequency for the I2C. I tried a few differet vaues. When I use the CPU clock speed (85 MHz), it doesn't hang. When I start up, the I2C seems to be initializing correctly. It does not, however, recognize the RTC chip. I have selected the ds1307 driver. It does probe for the RTC. The RTC is an M41T0, not an M41T00. This makes it quite difficult to google anything on the chip. - Altera_Forum
Honored Contributor
Please check your data sheet or user guide of the i2c daughter board to find out the exact part number.
What is the result of i2cdetect? Please note that you must match the i2c board info with the bus number, i2c address and i2c part in config.c, - Hippo - Altera_Forum
Honored Contributor
I have verified: M41T0.
Here is the relevant output from boot:
And when I run i2cdetect:i2c /dev entries driver rtc-ds1307: probe of 0-0068 failed with error -5 i2c-0: I2C OpenCores Bus Adapter, MMIO = 0x2120C00, irq = 9 i2c-0: Using 85000kHz clock source
I have verified in the part data sheet that the device address is 0x68. I finally got my hands on the Microtronix driver, but it is in a full linux distribution, for nios2nommu. I'm working on getting the relevant pieces transfered into the MMU build./# i2cdetect 0 WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-0. I will probe address range 0x03-0x77. Continue? y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- - Altera_Forum
Honored Contributor
I think there are problems in your i2c setup from the i2cdetect output. I would suggest changing the interface to gpio because it is simple and easy to debug.
http://www.nioswiki.com/gpio - Hippo - Altera_Forum
Honored Contributor
I'm not quite ready to give up on the Microtronix I2C yet.
I think I have the Microtronix I2C driver compiled in, but it seems to have no connection to /dev/i2c-0 (so i2cdetect fails). Microtronix sent me their entire Linux distribution. (I think it is uClinux, as there is nios2nommu). I've copied over what I think are the relevant I2C files:- drivers/i2c/algos/i2c-algo-mtx.c
- drivers/i2c/algos/i2c-mtx.h
- drivers/i2c/busses/i2c-mtx.c
- include/linux/i2c-algo-mtx.h
- Altera_Forum
Honored Contributor
Sorry, I cannot help. I gave up i2c oc early and made gpio instead. It might be easier to modify the sopc design than fighting with a vendor driver. I cannot see the point to spend time on a simple i2c rtc interface.
- Hippo