openwrt I2C

http://wiki.openwrt.org/doc/hardware/port.i2c

I2C

This gives an overview for running I²C on your router. There are a few other OpenWrt I2C projects out there and they really helped me getting this up and running. In contrast to the other projects this one

  • uses 2 GPIOs of the router
  • does not need any external circuit

Hardware

I2C is bi-directional and needs pull-up resistors on both lines (10k is recommended). Most devices operate at 3.3V but some need 5V.

I2C over GPIO

You need 2 GPIO ports to add a 3.3V I2C interface to your router. Check if your router has some spare GPIOs available. The TP-Link MR3020 has 2 unused GPIO ports at R15 and R17. Otherwise you can use GPIOs used for LEDs. To avoid any influence from the old components disconnect the LEDs from those GPIOs (by removing the resistors.

Add a 10k pull-up resistor between GPIO ports and 3.3V. On the MR3020 GPIO 7 would be SDA and the GPIO 29 would be SCL.

Install and load the kernel module:

 

# opkg update
# opkg install kmod-i2c-gpio-custom kmod-i2c-core
# insmod i2c-dev
# insmod i2c-gpio-custom bus0=0,7,29
# dmesg | grep gpio
Mar 23 09:01:23 openwrt kern.info kernel: [   52.910000] Custom GPIO-based I2C driver version 0.1.1
Mar 23 09:01:23 openwrt kern.info kernel: [   52.910000] i2c-gpio i2c-gpio.0: using pins 7 (SDA) and 29 (SCL)

 

When loading the kernel module replace the values 7 and 29 with the GPIO-Pins you have choosen. If the GPIO-Ports are used as LED you may have to unload the kernel module for the LEDs:

# rmmod leds-gpio

I2C with 3.3V and 5V devices

If some of your devices need 5V I2C bus you can use a simple level shifter with 2 n-channel MOSFETs like the 2N7000. Connect the source-pins of the MOSFET to the 3.3V line, the gate pin to 3.3V and the drain pin to the 5V line. You also need the 10k-pull ups on the 5V-line.

 

http://see.sl088.com/wiki/WR703_GPIO/I2C_%E4%BF%AE%E6%94%B9

 

WR703 GPIO/I2C 修改

From 森亮号航海见识 {SLboat Insight;}
Jump to: navigation, search

更多研究

WR703 GPIO/I2C 修改/使用I2C

发现

  • 利用微妙神奇的GPIO7和29(两者都未被boot加载),进行自定义成I2C,再加个上拉电阻,这个小盒子就更神奇了
  • 一个i2c的gpio软件包看起来很神奇
i2c-gpio-custom
  • 有个看起来专门用来折腾i2c的工具
i2c-tools
  • 这一切都给C来操作硬件有了一个很基础的平台
  • 如果接到5V的I2C设备看起来还要做电平转换-I2C 电平转换
  • 取得3.3V的电平需要从主板上获得-WR703 PCB/3.3V电源
  • 硬件设计部分,参考自sqounk的反向工程
JustCapIt4502.jpg

探索

  • 它所在的位置
IMG_2937.JPG
WR703引出I2C的位置 - Flickr页面

 

困扰

  • AR9331的手册里没有GPIO29,真是诡异,是编码起点的问题吗
JustCapIt4518.jpg

音频见识

  • 让它支持比如sht21这种温度传感器听起来很不错
  • 让它支持温湿度传感器,听起来不错
  • 它们虽然自带也带有电阻,但是是pulldown拉低的,这里需要挖掉它们变成拉高的
  • 如果I2C小板子能够更简单的供电,3.3V那看起来就更好了
实际上看来从主板的任何一个地方,都可以在主电源里获得的3.3V的供电

一些修改的项目

buy1_cn船长发现的一个改造
http://pragti.ch/kippycam/2012/08/15/Adding-an-I2C-interface-to-the-TL-WR703N/
JustCapIt7399.jpg

所用组件

i2c-gpio-custom

  • 它定义i2c的用法是这个样子

trunk/package/i2c-gpio-custom/src 中的 i2c-gpio-custom.c – OpenWrt 沿途见识[1]

12 * The behaviour of this driver can be altered by setting some parameters
13 * from the insmod command line.
14 *
15 * The following parameters are adjustable:
16 *
17 * bus0 These four arguments can be arrays of
18 * bus1 1-8 unsigned integers as follows:
19 * bus2
20 * bus3 <id>,<sda>,<scl>,<udelay>,<timeout>,<sda_od>,<scl_od>,<scl_oo>
21 *
22 * where:
23 *
24 * <id> ID to used as device_id for the corresponding bus (required)
25 * <sda> GPIO pin ID to used for SDA (required)
26 * <scl> GPIO pin ID to used for SCL (required)
27 * <udelay> signal toggle delay.
28 * <timeout> clock stretching timeout.
29 * <sda_od> SDA is configured as open drain.
30 * <scl_od> SCL is configured as open drain.
31 * <scl_oo> SCL output drivers cannot be turned off.
32 *
33 * See include/i2c-gpio.h for more information about the parameters.
34 *
35 * If this driver is built into the kernel, you can use the following kernel
36 * command line parameters, with the same values as the corresponding module
37 * parameters listed above:
38 *
39 * i2c-gpio-custom.bus0
40 * i2c-gpio-custom.bus1
41 * i2c-gpio-custom.bus2
42 * i2c-gpio-custom.bus3
43 */

  • 在这里的定义里通道是bus0,sda是7,scl是29。

i2c-tools

  • 它包含一系列的工具集,甚至可以直接的操作数据
  • 包含一个扫描工具:i2c-detect
SLboat-Screen 2013-02-02 14.35.32.png[2]

见识

TP-Link TL-MR3020 - OpenWrt Wiki 沿途见识[3]

Adding I2C Bus
If you want to add I2C bus to your MR3020, you can use GPIO 7 and 29. Remove R15 and R17, then add pullup between 3.3v and gpio pin.


4e8de1081c9036db78032a9dc787966a.media.600x450.jpeg

69b2095066a3af15f8cd7231c78ce709.media.600x450.jpeg


Next step, add this line
i2c-gpio-custom bus0=0,7,29
to /etc/modules.d/99-i2c
and load i2c-gpio-custom

You can find more info in french here http://www.equinoxefr.org/post/2012/11/12/mr3020-et-i2c-avec-les-gpio/

FoneraHacks - fonera-i2c - Hacking guide to add I2C buses to "La Fonera" - La Fonera hardware and software hacks to control I2C bus - Google Project Hosting 沿途见识[4]

Atfer reboot, dmesg command should say something like that:

i2c /dev entries driver
Custom GPIO-based I2C driver version 0.1.1
i2c-gpio i2c-gpio.0: using pins 1 (SDA) and 7 (SCL)
Install i2c-tools
opkg update && opkg install i2c-tools
Probe I2C devices (i2cdetect)
Test using i2cset/i2cget (e.g. with PCF 8574)

Hacking and moding the TP-Link WR703N OpenWRT Wi-Fi router | Dangerous Prototypes 沿途见识[5]

TP-Link WR703N is a OpenWRT supported Wi-Fi router that comes with ‘only’ 4MB of flash and 32MB of RAM. If you are not satisfied with these, they are easily upgradable as described in the forum.

引用信息

以下是[WR703 GPIO/I2C 修改]所有用到的引用信息,向这些伟大的家伙致敬:
  1. Jump up ^ https://dev.openwrt.org/browser/trunk/package/i2c-gpio-custom/src/i2c-gpio-custom.c?rev=10979
  2. Jump up ^ http://www.equinoxefr.org/post/2012/11/12/mr3020-et-i2c-avec-les-gpio/
  3. Jump up ^ http://wiki.openwrt.org/toh/tp-link/tl-mr3020#gpios
  4. Jump up ^ http://code.google.com/p/fonera-i2c/wiki/FoneraHacks
  5. Jump up ^ Hacking and moding the TP-Link WR703N OpenWRT Wi-Fi router | Dangerous Prototypes, 见识于2013-5-28 22:44
posted @ 2015-01-26 16:09  fastwave2004  阅读(1488)  评论(0)    收藏  举报