GPIO and TTL serial


23 posts
by tech_monkey » Wed Apr 25, 2012 9:07 pm
Its been a long time since I've done any real serial ttl stuff so a little rusty. Am I right in assuming the RX and TX pins on the GPIO are actually ttl serial.

I really hope the answer is yes, as I have a couple of potential projects that use a TTL serial interface for coms.
http://www.casatech.eu
Posts: 130
Joined: Fri Mar 09, 2012 6:12 pm
by jbeale » Wed Apr 25, 2012 9:13 pm
They are 3.3V logic level. I believe more strictly speaking "CMOS" rather than "TTL".
User avatar
Posts: 2120
Joined: Tue Nov 22, 2011 11:51 pm
by mkopack » Wed Apr 25, 2012 10:24 pm
Right, you'll need to use some sort of level shifter chip to convert between 3.3V and 5V (TTL) if you want to talk TTL levels. But otherwise, it's the same...
User avatar
Posts: 242
Joined: Mon Nov 07, 2011 8:46 pm
by johnbeetem » Wed Apr 25, 2012 10:42 pm
3.3V LVTTL can usually inter-operate with 3.3V CMOS.  It it's 5V TTL you do need to protect the 3.3V pins with a level shifter or bus switch.
User avatar
Posts: 942
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Coast
by mahjongg » Wed Apr 25, 2012 11:57 pm
The "level converter" in this case is only needed to convert from 5V to 3V3 levels, and can consist of a simple voltage divider. the 3V3 level from a CMOS output needs no conversion for most 5V inputs.

You can create a simple attenuator to 3V by using a top 2K2 and a bottom 3K3 resistor, it will work even at high speeds, because the GPIO input is high impedance and its capacitance is relatively low, so the signal isn't degraded much.
User avatar
Forum Moderator
Forum Moderator
Posts: 6014
Joined: Sun Mar 11, 2012 12:19 am
by colin B » Thu Apr 26, 2012 3:54 am
If you need proper RS232 levels the MAX3232,ADM3222,ADM3202 or similar are 3v3 compatible.
On a clear disk one can seek forever
Posts: 120
Joined: Sun Mar 04, 2012 12:23 pm
by tech_monkey » Fri Apr 27, 2012 4:49 pm
So basically if I want to convert the pins on the GPIO to true TTL then I just need to convert the levels from 3.3 to 5V.

So just to confirm I have understood everything so far;

For TTL the level is defined as 0 when the voltage is below 0.6 V and a 1 when the voltage is higher than 2.0 V, no matter what the supply voltage is.

And for CMOS a 0 is defined as 0.6V as well but a 1 is when the voltage is higher than 1.65V.

Mind you if the 1 on GPIO is 2V then I could do a direct connect.

Also found this pdf document that might be of interest to others.

Now after I sort this out, which programming language do I choose, but that's another topic.
http://www.casatech.eu
Posts: 130
Joined: Fri Mar 09, 2012 6:12 pm
by Gert van Loo » Fri Apr 27, 2012 5:42 pm
I have posted already in several places that we use a TTL to RS232 USB converter cable from FTDI. So you can plug the Raspberry-Pi into your PC/laptop USB port and use any program that expects an RS232 port.
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2112
Joined: Tue Aug 02, 2011 7:27 am
by mahjongg » Fri Apr 27, 2012 5:59 pm

tech_monkey said:

So basically if I want to convert the pins on the GPIO to true TTL then I just need to convert the levels from 3.3 to 5V.

So just to confirm I have understood everything so far;

For TTL the level is defined as 0 when the voltage is below 0.6 V and a 1 when the voltage is higher than 2.0 V, no matter what the supply voltage is.

And for CMOS a 0 is defined as 0.6V as well but a 1 is when the voltage is higher than 1.65V.


Sorry, no!

You do not need to convert levels when you want to connect a GPIO output to a TTL (or CMOS) input. That is because the CMOS output levels of the GPIO (0V for L and 3V3 for H) are fine for both TTL and 5V CMOS inputs.

The level conversion is needed for the 3V3 inputs of the GPIO, because they cannot tolerate 5V! If you tie 5V from a TTL (or CMOS) output directly to the GPIO input you may therefore damage the GPIO input because large currents will run from the GPIO input pin through a diode in the GPIO logic into the 3V3 supply of the SoC. At the very least you must use a resistor to limit this current, but a better way is to convert the 5V output level to 3V, with a resistor divider.

This is simple to do with a resistor divider like so:

2K2

5V in ——/////—+— 3V out
3K3    |
GND  —–/////—-
User avatar
Forum Moderator
Forum Moderator
Posts: 6014
Joined: Sun Mar 11, 2012 12:19 am
by tech_monkey » Fri Apr 27, 2012 8:37 pm
Excellent, and many thanks. Forgot about the TTL o/p to 3v3 i/p

As I said when starting this post, I am very very rusty on things like this. Its been a very very long time since I have attacked a serial port of any description with a soldering iron. And probably even longer with voltage divider stuff.

Right,  now on to programming languages. :)

Will post this as another topic.
http://www.casatech.eu
Posts: 130
Joined: Fri Mar 09, 2012 6:12 pm
by tech_monkey » Fri Jun 01, 2012 11:21 pm
While doing further investigations on potential hardware needs came across this small PCB http://www.sparkfun.com/products/8745, considering that to build a resistor divider will cost about the same it looks like a good deal.
http://www.casatech.eu
Posts: 130
Joined: Fri Mar 09, 2012 6:12 pm
by Pencoys » Thu Jun 07, 2012 6:50 am
Not sure how relevant this will be...
TTL serial into MAX232 (inverter/Buffer) inverts the TTL.
So if the TTL out of the Pi is true TTL serial then you need a non inverting buffer chip.
Not looked into this. Gomments Cert?
User avatar
Posts: 14
Joined: Fri Jan 13, 2012 8:48 am
by Gert van Loo » Thu Jun 07, 2012 1:35 pm
Pencoys wrote:Not sure how relevant this will be...
TTL serial into MAX232 (inverter/Buffer) inverts the TTL.
So if the TTL out of the Pi is true TTL serial then you need a non inverting buffer chip.
Not looked into this. Gomments Cert?


No, the RS232 levels and the TTL levels are always inverted. So your line vol tag is the opposite from your chip voltage. Do not add another inverter.
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2112
Joined: Tue Aug 02, 2011 7:27 am
by exartemarte » Tue Jun 19, 2012 10:40 am
Does anyone know for sure whether the gpio ports - specifically the eight general purpose i/o pins - have protection diodes? If they do then we should only need series resistors to limit the current rather than potential dividers to limit the voltage.

I ask because I'm thinking about an application that may have eight inputs, as well as other circuitry. The cost of a few resistors is not an issue but space probably will be, and I'd rather use eight resistors than sixteen.
User avatar
Posts: 316
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
by Gert van Loo » Tue Jun 19, 2012 1:06 pm
exartemarte wrote:Does anyone know for sure whether the gpio ports - specifically the eight general purpose i/o pins - have protection diodes? If they do then we should only need series resistors to limit the current rather than potential dividers to limit the voltage.

I ask because I'm thinking about an application that may have eight inputs, as well as other circuitry. The cost of a few resistors is not an issue but space probably will be, and I'd rather use eight resistors than sixteen.


No, there are no protection diodes.
There are internal clamping diodes which protect against ESD, but that is for static discharge, not for continuous over voltage.
For those who do not understand the difference between the two:

Static electricity can have only a limited amount of energy. It is basically a capacitor which is discharged over the pins. The ESD protection standard specifies exactly how big a capacitor to which voltage and the discharge curve. A 100pF capacitor charged to 1000V will hold 0.5*c*v^2 = 0.00005 Watts. That is discharged over 1500 Ohms so that energy is released in about 30 micro seconds. Then it can start cooling down as there is no more energy. (see http://en.wikipedia.org/wiki/Electrostatic_discharge)

A continuous voltage source can have infinite energy. Suppose you connect a 5V port which can deliver 25mA. The protection diode will clamp against 3.3V + diode drop of 0.3V. So the rest of the energy (5-3.6=1.4V) at 25mA should be 'removed' by the diode. Thus that diode will have to burn away 35mW watts every second. A factor 23.000.000 more then above.

(I hope I made no calculation errors above but you get the gist of it)
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2112
Joined: Tue Aug 02, 2011 7:27 am
by exartemarte » Tue Jun 19, 2012 2:34 pm
Thank you, Gert, but you are describing what happens when a 5v output is connected directly to a 3.3v input. I think you missed the point of the question I was asking, which was about using a series resistor which would dissipate almost all of the excess power.

Take, for example, the standard Picaxe download circuit - it uses a 22k series resistor to limit the current in order to protect the diodes. It works with TTL levels as well as with RS232, and I have used the same arrangement with AVRs.

From a 5v output port with a 22k series resistor the maximum possible current is 227uA. In practice it will be less because of the resistance of the input port.

Assuming 0.6v drop in the protection diode, the maximum possible power dissipated in the diode will be 136uW. In practice, again, it will be less because the current will be less than 227uA.

The essence of my question is this: is there something different about the Pi gpio ports such that the arrangements we routinely use to protect Pics and AVRs working at different voltage levels will not work for the Pi?
User avatar
Posts: 316
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
by ril_christian » Tue Aug 28, 2012 3:58 pm
Hi, I wanted to ask question about the GPIO and TTL serial connection available on raspberry pi.

I designed a transceiver on my project and planning to use raspberry pi B GPIO or TTL serial connection to interface my transceiver to a PC through ethernet port to make a data communication (transmit and receive data). My transceiver input and output are 3.3V LVTTL or LVCMOS, and I thought it is kinda possible isn't it?
Posts: 4
Joined: Tue Aug 28, 2012 3:47 pm
by winny13 » Sun Sep 16, 2012 8:38 pm
Hi Christian

How did you get on with your Transceiver project, I would be very interested in learning some more

Winny
Posts: 5
Joined: Sun Sep 16, 2012 3:41 pm
by pluggy » Mon Sep 17, 2012 11:10 am
I have a Pi hooked up to a DIY 5V arduino. The 3.3V TX into the arduino's 5V RX just works. I have a voltage divider consisting of a 10K & 18K resister to knock the 5V arduino TX down to 3.3 V GPIO RX.
Don't judge Linux by the Pi.......
User avatar
Posts: 2864
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by winny13 » Mon Sep 17, 2012 2:26 pm
Hi pluggy
what is the purpose of your project

Winny
Posts: 5
Joined: Sun Sep 16, 2012 3:41 pm
by pluggy » Mon Sep 17, 2012 2:42 pm
Trade secret ;)

I want the critical timing of an arduino type setup (none of this multitasking, make the timing up as you go along type nonsense) but need the linux OS for what it does best like multitasking....

A bit of stripboard, a 28 pin socket, the Atmel 328 chip,3 resistors, a decoupling capacitor and a ceramic resonator pass for an arduino. I reckon the 150 ppm timing of the resonator is accurate enough for what I want. But when I say 10 milliseconds it has to be close, not when linux gets around to it.

Image

Cheap Arduino.

Image

Cheap Arduino mounted on slightly more expensive Pi
Don't judge Linux by the Pi.......
User avatar
Posts: 2864
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by winny13 » Mon Sep 17, 2012 3:25 pm
Hi Pluggy

thanks for info, I think you live up north? and seemed clued up on this sort of thing...can i get you to help me on a concept I have?...wmt02@hotmail.co.uk is my e address ,

cheers

Winny 13
Posts: 5
Joined: Sun Sep 16, 2012 3:41 pm
by pluggy » Mon Sep 17, 2012 4:10 pm
Email and PM (for confirmation its me) sent. Anybody could email you claiming to be me...... ;)
Don't judge Linux by the Pi.......
User avatar
Posts: 2864
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK