13th May 2007

i2c bus for La Fonera

Tags : ,

posted in Embedded |

The goal for my first try to use Fonera's GPIO is to get i2c working on the router. And now, it's done. Kernel module and user space programs are here.

 

My kernel implementation use 4 GPIO on SW1 (1-2-5-6) near the Ethernet connector. Pin 1 and 2 are respectively used for sending and receiving SDA signals. 5 and 6, for SCL signals.

The GPIO are connected to a 75LS05 (TTL hex inverter) used as level adapter and buffer. You can see schematic here (PDF).

On the software side, my module is based on i2c-parport-light. Linux i2c stack is very complete, all i have to do is to use bit-banging i2c API (2c-algo-bit module). My driver, i2c_gpio, is available here : http://www.lefinnois.net/fonerai2c/i2c-gpio-0.0.5.tar.gz. Take a look to the README file to get more information.

To test i2c bus, simply use i2cdetect from lm-sensors project. This tool can scan i2c bus to detect chips. Here is a adapted version for La Fonera as a ipkg source package : http://www.lefinnois.net/fonerai2c/i2cdetect.tar.gz. This file contain also ds75ioctl. It's a simple tool that can talk to DS75 thermal sensor.

Example :

insmod i2c_algo_bit i2c_debug=3 bit_test=1
insmod i2c_gpio inverted=1

In dmesg :

i2c-algo-bit.o: (0) scl=128, sda=16
i2c-algo-bit.o: (1) scl=128, sda=0
i2c-algo-bit.o: (2) scl=128, sda=16
i2c-algo-bit.o: (3) scl=0, sda=16
needed 1 jiffies
i2c-algo-bit.o: (4) scl=128, sda=16
i2c-algo-bit.o: GPIO adapter passed test.
 : hw routines registered.
i2c_adapter i2c-0: adapter GPIO adapter registered
i2c-dev: adapter GPIO adapter registered as minor 0
gpio_i2c: module loaded
gpio_i2c: inverted outputs

i2c bus seem to work well. Let's try i2cdetect :

root@OpenWrt:/# i2cdetect -l
i2c-0   i2c    GPIO adapter  Algorithm unavailable

We have a bus here, so let's scan it :

root@OpenWrt:/# 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/n
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          XX XX XX XX XX XX XX XX XX XX XX XX XX
10: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
20: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
30: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
40: XX XX XX XX XX XX XX XX 48 XX XX XX XX XX XX XX
50: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
60: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
70: XX XX XX XX XX XX XX XX

Hey ! There is something at 0x48 :

root@OpenWrt:/# ds75ioctl -d /dev/i2c-0 -a 0x48
23.81

23.81°C. It works !

This entry was posted on Sunday, May 13th, 2007 at 11:22 am and is filed under Embedded. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

There are currently 14 responses to “i2c bus for La Fonera”

Why not let us know what you think by adding your own comment! Your opinion is as valid as anyone elses, so come on... let us know what you think.

  1. 1 On May 16th, 2007, RoD said:

    "23.81°C. It works !"

    YOU DID IT !

    That was only to make you smile, i know you like my private jokes buddy ;)
    Great idea to translate all your hacks in english. You are famous in France, i hope you’ll be in da whole world ! (next step in the "dominating world" program). One last thing to do before this … saving the cheerleader ! :D

  2. 2 On May 25th, 2007, skizzo3000 said:

    Hi,
    i have installed your mods on openwrt 2.6 but when i load i2cgpio with insmod command it tells me GIPO BUSY …
    I tried to cancell all modules and reinstalled but the problem is the same.

    What can i do ?

    Thanks Skizzo3000

  3. 3 On May 26th, 2007, Lefinnois said:

    What is the exact message in dmesg output ?

    i2c_algo_bit, when loaded with bit_test=1 try to test the port like this :

    1 - read if SDA=up SCL=up

    2 - pull SDA down and must read sda=down scl=up

    3 - put SDA up and must read SDA=up SCL=up

    4 - pull SCL dow and must read SDA=up SCL=down

    5 - put SCL up and must read SDA=up SCL=up

    If 5 steps are ok, the driver can register.

    Don’t forget to use inverted=1 when insmod i2c_gpio with 74HC05 ic.

  4. 4 On May 28th, 2007, skizzo3000 said:

    Thank you very much !

    Now is all OK ! I made one bad solder in one pin of 74hc05.

    P.S. What do you think about this IC TI P82B96P…. only one IC and 2 R.

    Sk3

  5. 5 On May 28th, 2007, panther said:

    I am so glad someone has finaly taken the time to implement an I2C driver for the fonera!

    Now i’ll finaly be able to add a port expander to my fon and finish my wifi rc car project.

    You might want to compile this into an ipkg for the current kamikaze build of openwrt, just so other people can more easily add it.

  6. 6 On May 30th, 2007, JunkyJorje said:

    Can you go into detail as to how you created the fonera toolchain? I created the toolchain following this webpage blogantastico.blogspot.co… but when i compile a simple "hello wrld" program it will not run on the fonera. it either says its not allowed, or it returns an error about a paranthesis missing (it says this when running, it compiles fine though on my computer)

  7. 7 On May 30th, 2007, Lefinnois said:

    Try this :

    http://forum.openwrt.org/viewtopic.php?pid=45838

    It’s a good way to start

  8. 8 On June 1st, 2007, JunkyJorje said:

    thx much Lef!

  9. 9 On June 13th, 2007, jackalope said:

    Great project! Do you have stats on this i2c implementation? What;s the throughput rate? I’d like to attach some i2c memory chips and see what I can get.

  10. 10 On June 19th, 2007, GCL said:

    Hello!
    The SN74LS05 is the Open Collector version of the Hex Inverter SN74LS04. But you’ve got the general idea.

    SN75 is typically used for interface parts and some linear ones.

  11. 11 On July 15th, 2007, dillon said:

    hi,
    i would like to know more about your linux platform (fonera),where would i can find more information?

    can we able to compile a kernel and put it into this fonera?

    what are the capabilities fo fonera SdRAM,flash?

    thanks u for helping linux enthusiast who is looking for cheap linux box
    dillon

  12. 12 On July 29th, 2007, Bob Keyes said:

    Getting I2C in La Fonera is a useful accomplishment! Any thoughts about putting a 1-wire interface in?

  13. 13 On August 23rd, 2007, Ryan said:

    Hi,

    great work, am attempting myself as I plan to do this project too!

    1 question though: does this support v1 v2 or v2.1 of the i2c specification?

    Thanks

  14. 14 On March 19th, 2008, Werner Teeling said:

    As for the temperature sensor: can the DS75 (made by Maxim) be replaced with a LM75 (made by National Semiconductor) ?

    The DS75 seems to be unavailable in The Netherlands.

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image