DIYstompboxes.com

DIY Stompboxes => Digital & DSP => Topic started by: lukatosh on July 22, 2021, 07:26:53 PM

Title: 3.3v and level shift to 5V on SPI lines
Post by: lukatosh on July 22, 2021, 07:26:53 PM
Hello! Best regards From Chile.

I Would like to ask about SPI protocol. Hope you can help me.

Well, I'm working on a MIDI controller... I'm using a STM32F401 as main uC to control 4 cascade 74hc595 shift register's using SPI to manage a 7segment display and some RGB leds so the user can know if it is on preset A from bank 1, 2 or 3. (I'm taking care of the current draw to not exceed the 595 limit)

The main concern is about the UC SPI lines... They work with 3.3v "high" values but the 74hc595 (powered with 5v) is specting a 5x0.7=3.5v High value.  Without doing any level shift, it works great, but i would like to make a reliable design.  Then.. I've looked at the datasheet and it says that uC  MISO, MOSI and SCK ​pins are 5v tolerant so can I just simply use some pullup resistors to "shift" the 3.3v to 5v signal? or definitly i need to think on a level shifter or buffer IC that can translate the line level?

Since SPI works detecting signals falling edge, the resistors pulled to 5v should not be a problem ...

I know that there is an 74hc"T"595 versiĆ³n that consider a 2v minimum signal as "high" but the 74HC595 are cheaper and i have a lot of them already.

On the protoboard, the pull up resistors do the work, everything works ok. Even iv'e shifted the signal using a 74HCT14 Hex inverter. Taking care of inverting twice the signal, everything works ok... but the concern now is about CURRENT.

The buffers or level shifters that are available on my country can only sink/source 8mA. Is this enough to feed SCK, MOSI, MISO lines that are connected to 4 shift register? How much current is involved in SPI transmition?

I hope I have made myself clear!

Thanks so much for your help and knowledge. Stay safe!

Title: Re: 3.3v and level shift to 5V on SPI lines
Post by: Sweetalk on July 23, 2021, 05:29:57 AM
You can do a Level Shifter with a MOSFET to keep everyone happy. Something like this:


(https://i.postimg.cc/qzQ9MypM/Level-shifter.jpg) (https://postimg.cc/qzQ9MypM)

I think that a BS170 or a 2N7000 will do the trick as well

Saludos!!
Title: Re: 3.3v and level shift to 5V on SPI lines
Post by: niektb on July 23, 2021, 04:23:49 PM
I know that these approaches work well with open-drain protocols (such as I2C) but doesn't this do weird stuff with push-pull (SPI)?