2
\$\begingroup\$

I need to convert the levels of the SPI and I²C busses of a 5 V microntroller to a 3.3 V card reader and EEPROM memory so I chose to use the 74LCX245 since it's a bidirectional transceiver.

But it's only unidirectional at the end because you've to set a pin to tell it in which direction to translate the levels.

Can I still use it? Since SPI and I²C have data lines that need to enter to the microcontroller they will be 3.3 V. Because it will translate "Microcontroller -> 74LCX245 -> card reader", but there is no way to shift the data coming out of the memmory card with the same transceiver.

Microcontroller: PIC 18F2550

Is there any way to do it? Using the same device or should I end using the N-channel transistors?

\$\endgroup\$
  • \$\begingroup\$ Can you give us part numbers and datasheets of the microcontroller, card reader and (E)EPROM? \$\endgroup\$ – user17592 Apr 21 '13 at 14:01
  • \$\begingroup\$ Most of the time, a 5V chip will be able to read a 3.3V bus. Also, some 3.3V devices are '5V-compliant', which means they don't care if you give them 5V instead of 3.3V. \$\endgroup\$ – user17592 Apr 21 '13 at 14:02
  • \$\begingroup\$ Could you use PIC18LF2550 and power the whole circuit at 3.3V? \$\endgroup\$ – markrages Apr 21 '13 at 21:20
1
\$\begingroup\$

As you already know, the 74LCX245 is bidirectional, but the direction has to be configured with a pin. So the I2C master would need logic to toggle the pin from transmit to receive whenever it is done talking, so that it can receive the acknowledgement. Since you're not implementing the I2C control block, but just using one, and it does not expose the signals which indicate the transmit/receive transitions, driving this transmit/receive pin will be difficult, but it is not provably impossible.

Therefore, the answer to your question can I still use it? is yes, I think. You'd need a circuit which tries to guess when the master is in a transmit state. This might be done by monitoring SDA and SCL to detect the passage of the start and stop conditions which basically indicate that the master is taking the bus and releasing the bus. When the master wants to speak, it will first pull SDA low. Basically, at the point it seems like a good idea to immediately put the 74LCX245 into transmit. What's coming next is the clock edge transition which indicates the start. But you don't want to delay the passage of the SDA pull down, so that the slave devices get a clear start condition. Then later if you see SDA going high while the clock is also high, that's a stop condition, and the chip can be flipped to receive.

One problem is that the chip has a just single global pin for flipping direction of all of its lines. You don't want to change the direction of the SCL line, which always goes from master to slaves. You never want to throttle the clock, even for a moment. So if you insist on using nothing but the 74LCX245, you will need two of them.

Another consideration is that the chip does not have open-drain outputs, but rather buffered ones. This could present a problem in two ways:

  • When the 74LXC245 drives its output low, the output will be expected to sink the current from the pull-down resistors on the bus. Luckily, this is fine since the datasheet lists ±50mA as the maximum output sourcing or sinking current.

  • A problem occurs if the 74LXC245 is configured to transmit and drives a high state onto the bus, while it so happens that a device pulls down the bus, also trying to transmit. The transmitter's buffer is then feeding current directly into the device's drain, which is nearly shorted to ground. Perhaps some small resistor could defend against this: large enough to limit current, but small enough that the logic level can be pulled down sufficiently close to zero (since that resistor will pair with the pull-down resistor on the bus to form the bottom of a voltage divider).

  • In regard to the previous point, you should probably make use of the global disable which puts both sides into high-Z. I.e. determine when the bus is completely idle and turn off the chip. Prior to detecting when the master wants to transmit, the chip should not be in receive mode because then it could drive the master's drain. Ideally you want the chip in bilateral high-Z mode, and from there, go to transmit. Then to receive (for the reply fro the device) and then back to high-Z.

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ RE: "SCL line, which always goes from master to slaves", this is not true in a multi-master system, and it is not true if the slave implements clock-stretching (however not very many slaves do this). \$\endgroup\$ – The Photon Apr 21 '13 at 17:13
  • \$\begingroup\$ Voted because the multi edits and constant adding of information. Plus you refered to my question and explained with it wasn't going to be useful to my purpose. \$\endgroup\$ – Sein Oxygen Apr 21 '13 at 22:54
  • \$\begingroup\$ Agreed with Photon: I2C really needs bi-directional shifting, as the slave will almost certainly need to stretch the clock after decoding the address. Similarly, SPI can't really be run with a single configuration pin, because the slave sends to the master at the same time as the master sends to the slave. \$\endgroup\$ – Jon Watte Jul 30 '13 at 3:46
4
\$\begingroup\$

I don't know of any way to use a '245 chip to do level translation for I2C. As you point out, I2C doesn't include any signal that can be used to control the DIRection pin of the '245.

The canonical method for I2C level translation looks something like this:

enter image description here

When the 5 V side pulls low, the 3 V side is pulled low through the body diode of the FET. When the 3 V side is pulled low, the FETs act in common-gate configuration to pull the 5 V side low. Selection of the FETs is fairly fussy, so don't just stick in any old FETs you have lying around.

A google search for "I2C level translator" also gives several hits from NXP, TI, Maxim (and probably others) showing that they make chips specially for this function. These chips basically include the circuit above with some "speed-up" circuit to enable reaching higher bus speeds.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Yes, I already know this solution. You're mixiing the things. I2C doesnt set the translation direction. The 74LCX245 has a pin indicating wich way translate the levels, not the I2C. Please check my question again. \$\endgroup\$ – Sein Oxygen Apr 21 '13 at 15:30
  • 1
    \$\begingroup\$ @SeinOxygen, The '245 has a direction input pin. It deosn't inidicate which way to translate, it needs to be told. But I2C doesn't have any output that you could use to tell it. \$\endgroup\$ – The Photon Apr 21 '13 at 15:46
  • \$\begingroup\$ This is how I would do it, except I would use 2.2 kOhm pull-ups to make sure to drive the I2C fast enough for 400 kHz or 1 MHz frequencies. \$\endgroup\$ – Jon Watte Jul 30 '13 at 3:47
0
\$\begingroup\$

There are a lot of methods to do "level conversion", and the forum thread 3.3 Volt to 5.5 Volt Octal TTL line Level Conversion is very useful.

You can use a voltage devider if you don't need a lot of speed (I don't know if this will work with you).

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.