3.3v to 5v inverter by bc547

i was wondering is there any method convert the 3.3 v logic of sdcard to 5 v of arduino bu using NPN or PNP transistors like bc547 and bc557. do we need to use level shifter ic and so then to use which ic
i have an SD breakout board

You can indeed.
The diagram attached works for both BJT's and MOSFETs (though for FETs you omit the 4.7k resistor).
It is also bidirectional so can shift up and shift down.
It is non-inverting so won't mess around with the signal.

For SD cards though you can just get away with a 1.8k and 3.3k resistor forming a potential divider to shift the signals from the Arduino down to 3.3ish volts. For the MISO signal, you can just connect it directly to the arduino as it will happily register 3.3V as a logic 1.

(P.S. Sorry for the zigzzaggy resistors, the program I drew that in favours those to the box ones)

Transistor Level shift.png

Mind that for fast signals (ie sdcard's one) you need to drive the CMOS inputs (ie sdcard's inputs) with low impedance output drivers (ie push-pull as it is with atmega). The transistor level shifter might work with TTL logic, but with high impedance CMOS inputs (ie 10Meg || 10pF) it will not maintain the fast edges (because ie low->high transition will be done by 10k push only)..
Better you use low value resistors dividers or a none-inverting driver..

Yeah, that circuit works best when you replace the BJT with a MOSFET. But it shows that it is possible to use BC547s for this purpose.

I have use just resistors in the past with no issues at all.

Resistors fail for some newer SD cards that have edge detectors. The SD specification requires clock rise time and fall time to be less than 10 ns.

Worse is the fact that the errors in write data won't be detected. There is no CRC by default since Arduino has no hardware support.

The latest version of SdFat supports software CRC but this slows transfers.

so i think the best way is to use mosfet's. i am thinking about BSS138.
but the device needs to be truly bi-directional as there will be communiction between arduino and SD card

That MOSFET should be fine.

Gate goes to B in the diagram
Source goes to E
Drain goes to C

Remove the 4.7k resistor and connect the gate directly to 3.3v

You may find if there is a lot of stray capacitance that you need to reduce the two other resistors down to about 1k to get a fast enough rise time.

There is an adapted version of the circuit which uses two MOSFETs to drive the signal which means that both rising and falling edges are sharp.

See the resistors dividers below - the more traditional values with 1k8/2k2 and 220/390 as well. You can go even lower with resistors' values, though.
And the mosfet variant :slight_smile:

what oscilloscope did you use?

I would assume it is a software simulation. In reality the MOSFET version doesn't result in those peaks.

Hi
Ist this shifter work for NeoPixels Stick and Strips on Data?
PIC32 (3.3V) to Neopixel (5V) or Arduino Duo (3.3V) to Neopixels (5V).