STM32 and 5v devices: Your favorite level shifter? Or open drain with pullup? - Page 1
Forum section: electronics / general

author: rhodges
author_rank: Frequent Contributor
timestamp: February 08, 2020, 09:08:00 pm
content: I have a working build system for STM32F103 and STM32F030, and have hardware debugging. Now I am looking at porting my device libraries from STM8 to STM32. These include LED displayswith the MAX7219 and TM1638 controllers, which require 5v Vdd and 0.7 Vdd high signal levels. I may also need those levels for the HD44780 LCD controllers.Looking at the STM32F030 datasheet, most of the pins are "TTa" with a maximum voltage of 4.0, and a maximum injected current of 5ma. This implies to me that those pins are diode clamped to 4.0 volts and I am allowed to use a pullup resistor, up to 5ma. So if I use a 1k pullup to 5v and select open drain, the injected current would be 1ma (high) or 5ma (low). Question: Even if I MAY do this, is it a good idea?A nicer option would be to use a level converter. Maybe a hex buffer in 74HCT? Is there a favorite choice for something this simple?Thanks!

author: oPossum
author_rank: Super Contributor
timestamp: February 08, 2020, 09:20:03 pm
content: Single: 74AHC1G125Quad: 74AHC125Octal: 74AHC541Single bidir: 74LVCH1T45Octal bidir: 74LVC8T24574AHC family can go from 5V to 3V3 when powered with 3V3.74HCT familty can go from 3V3 to 5V when powered from 5V.

author: mikerj
author_rank: Super Contributor
timestamp: February 08, 2020, 09:23:18 pm
content: Quote from: rhodges on February 08, 2020, 09:08:00 pmIn short, no. 4 volts is the value given in the absolute maximum table. As stated in the datasheet, these values are damage limits, and correct operation (or indeed any operation at all) is not guaranteed. These pins will be tired to ground and Vdd via ESD protection diodes, and a good design will never deliberately forward bias these diodes since no safe maximum current is provided for normal operating conditions, only an absolute maximum.For inputs you are in luck, many of the STM32 GPIO pins are 5v tolerant when configured as an input. For 5v output logic you need some kind of level translation.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 09, 2020, 04:53:59 am
content: Quote from: mikerj on February 08, 2020, 09:23:18 pmThe 5mA figure is functional, not damaging.Note that analog functions may still be disrupted, especially ADC functions on respective pins. These usually end up with a 0mA current injection limit.As for level translation, a schottky clamp diode is a good idea, with a series resistor if necessary. This allows you to use 5V CMOS into 3.3V inputs, or TTL directly (which pulls up to ~3.5V normally, so maybe kinda doesn't even really need the clamp diode, but it's nice to have).Going the other way, 3.3V is a bit low for guaranteed 5V CMOS thresholds, but can be raised a bit with a voltage divider (series resistor from output to input, pullup from input to +5V), or is fine for TTL.Tim

author: techman-001
author_rank: Frequent Contributor
timestamp: February 09, 2020, 06:01:51 am
content: Quote from: rhodges on February 08, 2020, 09:08:00 pmThe STM32F103 electrical document (August 2015 DocID13587 Rev 17 page 1 of 117) has this to say:"Up to 80 fast I/O ports 26/37/51/80 I/Os, all mappable on 16 external interrupt vectors and almost all 5 V-tolerant"You need to use the "FT" (five volt tolerant) not "TTa" pins I think.

author: edavid
author_rank: Super Contributor
timestamp: February 09, 2020, 06:06:56 am
content: Quote from: oPossum on February 08, 2020, 09:20:03 pmDon't you need to use 74AHC parts to go from 5V to 3.3V? The 74AHCT datasheets don't say anything about 3.3V operation.

author: Siwastaja
author_rank: Super Contributor
timestamp: February 09, 2020, 07:14:56 am
content: One hack I have resorted to is to power the (CMOS) devices from 3.6V and 4.5V. Many 3V3 devices list 3.6V as the functional max, and many 5V devices list 4.5V as the functional min. Of course, you lose any margin against regulation inaccuracy. If you use adjustable regulators anyway, or find suitable parts easily, this is zero extra parts and no extra circuitry at all.This way, high level of 3.6V is 80% of the Vdd=4.5V, above the typical 70%-ish CMOS threshold.Of course, such a hack is more sensitive to noise, and note that when charging the line RC parasitics, the last few dozen millivolts takes the longest, hence you'd want to have some "overdrive" over the minimum reliable detection threshold.Open drain with pull-up is obvious, but only works with 5V tolerant pins, so need to be careful with pin mapping. Also note that it's limiting the output impedance to somewhere around 1kOhm min, so maximum speed drops due to line capacitance.

author: GeorgeOfTheJungle
author_rank: Super Contributor
timestamp: February 09, 2020, 10:38:24 am
content: Usually the problem with open collector + pullups is the positive going edges, the negative ones are always fast enough. What you need to do is check your positive edges with the scope, and find the highest pullup R (4k7?) that can bring the pin HI quickly enough for the kind of signals you're dealing with. Slow signals can do with 10k that's for sure.

author: rhodges
author_rank: Frequent Contributor
timestamp: February 09, 2020, 01:14:58 pm
content: QuoteI am working with SPI, and the stm32f030f4 only has 4 5v tolerant pins. The SPI pins are not.I see the '103 does allow 5v on the 2 SPI devices, though. Maybe I should get SPI working with '103 first.

author: techman-001
author_rank: Frequent Contributor
timestamp: February 09, 2020, 03:06:05 pm
content: Quote from: rhodges on February 09, 2020, 01:14:58 pmI use the STM32F051 in UFN32 and it has SPI1 available as FT in alternate function, or both in the 48 pin flat pack upwards. The F030 is a kind of cut down variant I think.I doubt a lot would translate from the F103, so if your final target is the F030f4 I'd probably go with some level translator on it from the start. The F103 is a 16 years old now, and one has to be sure to read the errata

author: oPossum
author_rank: Super Contributor
timestamp: February 09, 2020, 05:19:12 pm
content: Quote from: edavid on February 09, 2020, 06:06:56 amYep. Memory failed me again. Original post corrected.

author: mikerj
author_rank: Super Contributor
timestamp: February 10, 2020, 12:26:15 pm
content: Quote from: T3sl4co1l on February 09, 2020, 04:53:59 amFair enough, I only saw the 5mA injected current value is listed in section 6.2 "Absolute maximum ratings". The I/O current injection characteristics in 6.3 does suggest that things should mostly work at this value, but also states it should be avoided.

author: Buriedcode
author_rank: Super Contributor
timestamp: February 10, 2020, 09:18:51 pm
content: These are generally the options I've used many times: For 3.3V/3V to 5V I use HCT buffers (244, 541 for easy routing 8-bit busses). For the other way, LCX (and LVC I believe), sometimes VHC but the VHC245 isn't 5V tolerant as its bidirectional - the output has a parasitic diode clamp to VCC. For bidirectional low frequency signals I tend to use the cheap 2N7000 with pull ups.HCT logic is still ubiquitous, and LCX is almost as common nowdays.

author: splin
author_rank: Frequent Contributor
timestamp: February 11, 2020, 04:44:57 pm
content: TI do a large range of level translators starting at around $.05:http://www.ti.com/logic-circuit/voltage-level-translation/products.html#sort=p1130;ascOther manufacturers no doubt supply similar.