3.3V to 5V level shifter for high speed serial

Hi All...

I need to connect the UART of a ATMega1284P to another device serial port. The 1284P will be 5V, the other device is 3.3V. So I think I need a bidirectional level shifter, but the ones I have found are not only expensive but have many, many pins. I prefer to avoid using resistors. Can anyone offer some suggestions?

Thanks...

skyjumper:
I prefer to avoid using resistors. Can anyone offer some suggestions?

My suggestion is to get over your aversion to resistors.

Another choice is to use transistors for level shifting.

Whats wrong with resistors? I am just curious.....

I had to do this same shift for comms with a PS2 controller. But it uses the dreaded resistors......

http://arduino.cc/forum/index.php/topic,80694.0.html

skyjumper:
Hi All...

I need to connect the UART of a ATMega1284P to another device serial port. The 1284P will be 5V, the other device is 3.3V. So I think I need a bidirectional level shifter, but the ones I have found are not only expensive but have many, many pins. I prefer to avoid using resistors. Can anyone offer some suggestions?

Thanks...

Well serial communications as implemented in a AVR chip on a arduino board is not bidirectional as they use separate send and receive pins, so you only require two unidirectional conversions at most. In reality a 3.3 volt output serial signal wired to a 5vdc logic input pin normally works fine as 3.3 is just marginally a little higher then the minimum legal high value for 5 volt logic as defined by the AVR chip. And sending a 5 volt signal logic directly to a 3.3v input pin can me made directly if the 3.3vdc input pin is stated to be '5 volt tolerant'. If it is not tolerant, a simple 2 resistor voltage divider is more then enough to implement the conversion. One only needs the fancy methods of conversion if indeed you are dealing with a single bidirectional signal wire such as used in the I2C buses and such and the 3.3 volt device is not '5 volt tolerant', but not needed for 2 wire (plus ground wire) asynchronous serial communications links.

What do you mean by "high speed serial"?? 10Mbaud??
Up to ~500kbaud you may use resistor divider without any problem, the smaller values the better :slight_smile:

pito:
What do you mean by "high speed serial"?? 10Mbaud??
Up to ~500kbaud you may use resistor divider without any problem, the smaller values the better :slight_smile:

This application will run at a maximum rate of 921.6 kbaud, and speed is exactly my concern.

Resistors as used in a simple divider network do not cause any 'speed' degradation. Resistors are used at all frequencies including microwave and above. Only if resistors and capacitors are combined does a RC time constant factor come into play that can effect signal speed through such an RC network.

Okay, thanks everyone. Why is there such a reluctance to using resistors as level shifters when connecting SD cards to the SPI bus?

Speed. My understanding is that dedicated level shifters or a well-designed circuit like the BSS138 make for fast switching with nice square signals.

Quite important for fast SD cards, apparently.

So I guess there is a difference of opinion on the speed issue. But let's set that aside for a minute.

I can use a simple resistive voltage divider (a 1K and a 2K) to knock 5V down to 3.33V. No capacitors, so I guess there is not a speed issue. But, I have a 3.3V signal coming into my ATMega1284P. Will the uC reliably read this as a logic high? If not, then maybe I need something like a TXS0102?

It "should" since the minimum "high" voltage on a digital input is 2.7vdc for an Atmel running on a 5VDC power supply, IIRC.

Question is though, do you feel lucky? Since I rarely breadboard, I rely on solutions that ought to work 100% of the time. I have had great success with level-shifting via the TXB series on the SPI bus. So, I'll keep adding the three chips necessary (one IC, two decoupling caps) and call it a day.

I have had great success with level-shifting via the TXB series on the SPI bus. So, I'll keep adding the three chips necessary (one IC, two decoupling caps) and call it a day.

And that is not necessarily a bad or even a 'overkill' attitude to take. I just jumped in to try and squelch the thought that some how a resistor(s) is a slower device then an FET transistor(s), when in fact the opposite is closer to the truth. Every transistors comes with a specified 'speed' limitations, it's stated in their datasheets. This limit may or may not effect anything depending on the application it is used in. Resistors don't have any 'speed' limitation unless excessive lead length, circuit layout, or wire wound resistors are included in a circuit analysis, which equally would apply to transistors also.

Lefty

Constantin:
Question is though, do you feel lucky? Since I rarely breadboard, I rely on solutions that ought to work 100% of the time. I have had great success with level-shifting via the TXB series on the SPI bus. So, I'll keep adding the three chips necessary (one IC, two decoupling caps) and call it a day.

And at $1.47 for the chip, its pricy but I can live with it. After doing some reading though, it seems TXB series workk for SPI, TXS series works for I2C. Which is the proper choice for serial? It seems that the TXB series needs the device to source 2mA to drive it, but the TXS does not.

This is with res dividers @ 2Mbaud, 20pF stray capacitance. You may use smaller resistors thus make edges even steeper..

skyjumper:
Which is the proper choice for serial? It seems that the TXB series needs the device to source 2mA to drive it, but the TXS does not.

Well, there are at least two ways to find out... post at TI or Adafruit (their forums are pretty good) or buy the Adafruit txb breakout and just try it out. My guess is that the txb would work.

pito:
This is with res dividers @ 2Mbaud, 20pF stray capacitance. You may use smaller resistors thus make edges even steeper..

Here is the analysis from Hermann Shutte, who first popularized the BSS138 MOSFet approach (at least to my knowledge). Those are pretty steep and well-defined edges, however!

All I recall (and it's been a while) is that the level-shifting issue would usually rear its ugly head in SD card applications and that the resistor networks that "classic" SD cards used to work with would stop working OK as SD card speeds advanced. Maybe Mr. Greiman can chime in? I note that the current ethernet shield now features the 74LVC1G125 buffer chip. Presumably, for a reason.

My guess is that it's not the Atmel IC that is the issue, it's likely the SD card that doesn't feature a nice 100MOhm input impedance like the ADC in the Atmel 328P. For me, since the primary reason I need level-shifting is logging to a SDHC card, using a TXB-series chip is second nature.

Okay, I apologize that this thread is running on and on, and if it seems like I am beating a dead horse I apologize again.

That app note from NXP is great, thanks for linking that! One thing I had not mentioned is that the part I am connecting to also has a TWI port at 3.3V that I want to marry to the ATMega processor at 5V, so that was spot on.

So there are at least four ways to do this:

  1. Use a resistive voltage divider to knock the 5V down to 3.33V.
    Advantages: Cheapest solution, easy, uses very little space on the PCB.
    Disadvantages: Only works to change 5V to 3.3V, does not go the other way. Won't work for TWI.

  2. Use a single BSN20 per line.
    Advantages: Fast enough for at least TWI at 400 Kbaud, not sure about UART at almost 1Mbaud.
    Disadvantages: May not be fast enough for UART, moderate cost at $0.37US each, consumes a lot of space

  3. Use a pair of TXS0102 (one for TWI, one for UART)
    Advantages: No speed issues, super easy to use
    Disadvantages: At about $1.50 each, very high cost, lots of space consumed

  4. Use a buffer like a 74LCX125.
    Advantages: Very cheap (the TI version is $0.08 each each line), all 4 signals can be handled by one chip
    Disadvantages: ??

I worked on another project, with the help of Crossroads, that has an SD card. We did have some trouble with the level translation and ended up using a chip like a 74LCX125 (I have to check to be sure). I have to confess, I am not clear on how this works. The buffer output goes high or low depending upon the logic states of the input, but I don't see how the output voltage is controlled. I read the data sheet and didn't see how that works...

And yes, much of my concern with speed issues stems from my experience with the SD card issue. So perhaps I need not worry about it with other device.

Thanks again for the help everyone...

Constantin:

pito:
This is with res dividers @ 2Mbaud, 20pF stray capacitance. You may use smaller resistors thus make edges even steeper..

Here is the analysis from Hermann Shutte, who first popularized the BSS138 MOSFet approach (at least to my knowledge). Those are pretty steep and well-defined edges, however!

All I recall (and it's been a while) is that the level-shifting issue would usually rear its ugly head in SD card applications and that the resistor networks that "classic" SD cards used to work with would stop working OK as SD card speeds advanced. Maybe Mr. Greiman can chime in? I note that the current ethernet shield now features the 74LVC1G125 buffer chip. Presumably, for a reason.

My guess is that it's not the Atmel IC that is the issue, it's likely the SD card that doesn't feature a nice 100MOhm input impedance like the ADC in the Atmel 328P. For me, since the primary reason I need level-shifting is logging to a SDHC card, using a TXB-series chip is second nature.

skyjumper:
4) Use a buffer like a 74LCX125.
Advantages: Very cheap (the TI version is $0.08 each each line), all 4 signals can be handled by one chip
Disadvantages: ??

.
.
.

I read the data sheet and didn't see how that works...

Oh wait, I get it. Its can be powered by a wide range of voltage and all it does is turn on and off whatever voltage is tied to Vcc. So I would need two of them. To go from 5V to 3.3V I hook 3.3V up to Vcc, tie the OE pins to ground and then attach the 5V signal lines, and that switches on and off the 3.3V output. To go the other way I just do the same thing the other way with a different chip.

What makes the bss138 or txb approach so attractive is that these circuits are bidirectional. This is especially useful on circuits like twi or i2c where signals can originate from either slave or master on a shared bus.

Because of its inherent uni-directionality, SPI is easy to implement with inexpensive buffer chips. For other buses / hardware configurations / protocols, you have to figure out a way to enable/disable the buffer chip via the OE pin as needed. That may not be feasible with some types of devices /buses that do not feature a suitable OE signal output as part of the package.

Another thing to keep in mind is that you may be able to economize on level-translating chips as long as whatever target voltage is within spec for all devices. Of course it's best to hit the specification bang on but spec sheets wouldn't be publishing allowable ranges if the designers had not anticipated this sort of thing happening in the real world.

Constantin:
What makes the bss138 or txb approach so attractive is that these circuits are bidirectional. This is especially useful on circuits like twi or i2c where signals can originate from either slave or master on a shared bus.

Because of its inherent uni-directionality, SPI is easy to implement with inexpensive buffer chips. For other buses / hardware configurations / protocols, you have to figure out a way to enable/disable the buffer chip via the OE pin as needed. That may not be feasible with some types of devices /buses that do not feature a suitable OE signal output as part of the package.

Got it, thanks!

Another thing to keep in mind is that you may be able to economize on level-translating chips as long as whatever target voltage is within spec for all devices. Of course it's best to hit the specification bang on but spec sheets wouldn't be publishing allowable ranges if the designers had not anticipated this sort of thing happening in the real world.

Perhaps with this device:

I could use half of it for the I2C bus and the other half for the UART. Yes the UART lines are unidirectional but who cares, it will still work. I found some interesting reading in these here:

So apparently I don't need pullups because the level translator has 10K pullups internally. But that presents a problem. The device I am interfacing with already has pullups on the bus, and they can not be disabled. This is fine for the 3.3V side, but the 5V side might be a problem.

Also, the data sheet says to pull OE to ground through a resistor, the value of which depends upon the current capability of the driver. But which side, and how would that be calculated?