OpenWrt Forum Archive

Topic: WR703n i2c mod - gpio voltage level

The content of this topic has been archived on 11 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,
I finally got my new toy from china. I successfully flashed it with openwrt and despite my bad soldering skills I managed to remove resistors and attach wires to gpio pin 7 and 29. And it even seems to work.

Hovever I would like to connect i2c lcd which operates at 5v. I'm not sure if I get this right. Since i2c is open collector does this mean I can use 3.3v for the bus and separate 5v wire to power lcd (as far as i2c expander used in lcd understands 3.3v logic on the bus)?

And the second thing is I've read at this forum that gpios in this router are only 2.5v tolerant. Does it mean I need some level translation at router side? Or can I just connect bus to 3.3v using pullups and I will be fine?

I have just basic background in electronics so any help is appreciated.



EDIT:
After I did some research on i2c it seems to me I really need a level shifter.

Vc1 2.5V? ----------------       ------------ Vc2 5V
                 |      |       |   
                 X      |       X   
                 R      |       R   
                 X      |       X   
                 |      |       |   
 gpio-7 --------------[FET]------------------ expander

same for gpio-29

I would use something like this. Just not sure if this is good for the gpio pin. I watched the datasheet of ar9331 and there is not much information about gpios. Like what pull-up voltage should I use? How much curent can gpio handle when it's in low state. This limits mimal value of pull-ups I guess?

(Last edited by loblik on 1 Nov 2013, 01:16)

The details of that simple level shifter can also be found here: http://www.hobbytronics.co.uk/mosfet-vo … -converter
So far, I just tested I2C at 3.3V for a short time on a WR1043ND, which has a similar SoC. But I guess, you should measure the voltage when setting the GPIO to output and high, and use that voltage on the pull-up.

Thanks all for sharing your experience with this device. I finally got it to work.

I meassured the output voltage when gpio is set to high and it's about 2.7V.
So I wired up a simple level shifter and used 2.5V on the lower side. The only part which might be hard to get
is N-FET with proper threshold voltage. I had to use BSS138 with surface mount package. Hovever it work's
just fine in this setup.

I've attached an i2c LCD to the bus to test the connection. Whole setup is shown in following picture.

PunBB bbcode test

The LCD is running for several hours without any problems. Just keep in mind that bitbanging costs CPU time.
So using the bus heavilly without proper i2c hardware can keep your CPU too busy to do other things.

I'm currently writing simple C linux library to control the LCD and commandline tool for use in scripts.
If it is going to be usable I can make it as openwrt package one day.

Thanks again

That is awesome! Care to draw out a schematic? I would venture to do so but mistakes would easily slip in if I just have that picture to go on.

Great work.

Nice work!

You can probably get rid of the 78L02 voltage regulator: there is a test point on the TL-WR703N PCB bottom side labeled "TP2V5" west of  the Q1 transistor close to the USB connector on C101's south pin, +2V5 supply is also available on R2/R3 north pin near the WiFi printed antenna tip:
http://img94.imageshack.us/img94/7828/tlwr703nbottomnotmirror.jpg

As for the I2C level shifter, if you don't feel comfortable soldering SMT components or don't have BSS138 FET on your workbench, you can buy a cheap level shifter from Adafruit for < $4:
[http://www.adafruit.com/images/medium/757_MED.jpg.

Squonk wrote:

You can probably get rid of the 78L02 voltage regulator: there is a test point on the TL-WR703N PCB bottom side labeled "TP2V5" west of  the Q1 transistor close to the USB connector on C101's south pin, +2V5 supply is also available on R2/R3 north pin near the WiFi printed antenna tip.

Thanks for the hint. I'm plannig to build simple expansion board providing i2c to 1-wire bridge and some i2c I/O expander (just using predrilled board, nothing serious). Then I could power the board with 5V and use regulators on the board or add other voltages to the router pinout. Not sure
which way is better.

Guzz wrote:

That is awesome! Care to draw out a schematic? I would venture to do so but mistakes would easily slip in if I just have that picture to go on.

There are several sources how to add software i2c to this device. Personally I followed the guide at wiki.
http://wiki.openwrt.org/toh/tp-link/tl- … ng.i2c.bus
Actually it's for mr3020 but it should be almost the same. Anyway to make sure you are removing right resistors you can find the pinout of the processor here.
http://wiki.openwrt.org/toh/tp-link/tl- … 331_pinout
Just follow the trace from the gpio pin at your board to make sure you are doing it right.

And as others mentioned the most tricky part is the soldering. If you don't have hot air gun it's probably better to add some more solder to the
resistor at first then heat the whole place with iron and gently remove it. Then use solder wick to clean up the area. But do NOT apply any horizontal force to the resistor. I'm quite bad at soldering and one of my pads went totally off. Then I had some hard time to solder the wire to the rest of the trace.

Once you have wires soldered you might add some level shifter since these gpios operates at 2.5V+- and most i2c devices are 3.3/5V. There are several sources on the net how to build this. There is a brief explaination how these shifters work, as MBS posted above.
http://www.hobbytronics.co.uk/mosfet-vo … -converter
For more details on level shifters in i2c applications you can read this paper.
http://www.adafruit.com/datasheets/an97055.pdf
Regarding the N-FETs to use. Most people go with the popular 2N7000 N-FET but this one has GS threshold probably to high for shifting from 2.5 to 5V. So I chose the BSS138. And it works quite nice so the one which Squong posted should also work since it uses the same FETs.
The second thing are pull-ups. Again there are tons of sources covering this topic. Basically with longer wires (higher capacitance) you need
lower resistors. However to pick up right value you should check the bus with osciloscope I guess. If you don't have one like I don't then start with 10k and then try some lower if it does not work well. I used 10k and it works fine. Just to mention using lower value pull-ups means more current
is flowing into the gpio when it's grounded (set to low).

So if I have 2.6V pull-up voltage and 10k pull-ups then the max current should be  0.26mA if I'm right.

Does anybody have a clue what is secure input current for the pin?

(Last edited by loblik on 29 Nov 2013, 13:38)

Is there somewhere some simple schematics for getting i2c working, I'm looking to add RTC clock to my OpenWrt based devices and RTC uses i2c bus.

I have tried following this article and wiki but this is over my head, and watching where each wire goes on the picture is not easy and one wrong connection and it doesn't work, and I have no idea where to start with troubleshooting...

So one both gpio pins need pullup voltage? One needs 3V and other 5V? Why? Why don't both use 3V or 5v?

valentt wrote:

So one both gpio pins need pullup voltage? One needs 3V and other 5V? Why? Why don't both use 3V or 5v?

No. The gpio pins use 2.5V as high voltage level. So both of them need to be pulled up to 2.5V. Since most i2c devices use 3.3V or 5V you have to use level shifter which is able to interconnect two parts of the bus with different voltages. Here is probably better schema.

shifter schema

Just be sure you connect the source pin of the transistor to the lower side. That means to the router gpio pin. Otherwise it won't work.
And if you experience connectivity or realiability problems you can try to lower resitors values as explained in the post above.

(Last edited by loblik on 3 Feb 2014, 07:49)

The discussion might have continued from here.