7

I am trying to interface a PS/2 keyboard to a MSP430 for a toy. The PS/2 keyboard runs off 5V, but the MSP430 microcontroller runs off 3.3V. So I have a 74LVC245 level shifter to convert between the two.

Now I have this, however, I have discovered that the PS/2 keyboard interface uses open collector signals, so that they can be driven from either end, and apparently using a 74LVC245 with these is complicated. This is the first time I've met such a thing; I'm mostly a software guy.

I'm not interested in sending commands TO the keyboard, only in receiving commands FROM the keyboard, so I never need to drive the data and clock lines from the microcontroller end. Is it sufficient simply to tie the keyboard signals to Vcc via a (large) pullup resistor, so that they stay high when the keyboard's not driving them (this is required by the protocol; if they're not high, the keyboard won't send). But this means that when the keyboard tries to bring the lines low, it's driving against the resistor, and I don't know what the implications of this are. And I don't know whether the 74LVC245 itself has its own pullup/pulldown resistors in the inputs.

Is this a good idea? If not, why, and is there any way I can make this work without having to build a proper driver circuit with resistors?

The 74LVC245 datasheet is here, for reference: http://www.adafruit.com/datasheets/sn74lvc245a.pdf

Nick Alexeev
  • 37,739
  • 17
  • 97
  • 230
David Given
  • 1,173
  • 1
  • 8
  • 15
  • If you're only interested in the outputs of the keyboard and they're open-collector, then you can use pull-up resistor tied to the 3.3 V rail and wire the keyboard's outputs directly to the microcontroller's inputs. You won't need the 74LVC245. – m.Alin Feb 24 '13 at 16:28
  • Off-topic, but do you have a link to good information on how to work with the PS/2 protocol with a micro? Wasted lots of weekends on it already... –  Feb 24 '13 at 16:41
  • 1
    @Camil: tonnes. Right now I'm looking at http://www.kbdbabel.org, which even has some protocol converter source for the 8051. There's also the PC keyboard FAQ at http://ilkerf.tripod.com/c64tower/F_Keyboard_FAQ.html. – David Given Feb 24 '13 at 16:52
  • @m.Alin Bah, wish I'd known that earlier. Just to double check: is that completely safe, given that I'm not allowed to drive a microcontroller input above 3.6V and the keyboard runs at 5V? – David Given Feb 24 '13 at 16:53
  • I don't want to discourage you, but all my experiences with PS/2 keyboards and mice required bidirectional traffic to get the devices initialized properly. I hope you will prove me wrong. – jippie Feb 24 '13 at 16:59
  • @DavidGiven Provided the outputs of the keyboard are really open-collectors and you pull the output high to the 3.3 V rail through a 10 kOhm resistor, then it should be safe. When the output of the kb is inactive, the output would be pulled by the resistor at 3.3 V; when the output of the kb is active it will pull the output to 0 V – m.Alin Feb 24 '13 at 17:42
  • Breadboarding it up (without the microcontroller plugged in!) shows that with a 12k pullup resistor (the closest I could find), the voltage on the clock and data pins is a bit over 4V. So I suspect that the keyboard isn't as open collector as it could be. Anyway, thanks, that's useful; if you write it up as an answer I'll upvote you... – David Given Feb 24 '13 at 19:39

1 Answers1

3

This is just an $0.02 thought, and not necessarily an answer.

Level shifting of a bi-direction open-collector signal sometimes is done in I2C bus. There are specialized level shifter ICs for I2C, such as PCA9306, which you could try to adopt for PS/2. There's another method, where level shifting is done with a MOSFET connected like this

enter image description here

This picture shows level shifting of 2 separate lines (obviously). More details in this app note by Philips (now NXP).

Nick Alexeev
  • 37,739
  • 17
  • 97
  • 230
  • Yes, and I wish I'd bought one! Given that I appear to have decided to work with 3.3V microcontrollers in a world where homebrew's designed around 5V (*cough*Arduino*cough*) it would be a wise investment. – David Given Feb 24 '13 at 23:08
  • @DavidGiven There are lots of good but 5V-intolerant peripherals. You would have had to deal with leve-shifting too, should you have chose a 5V controller. – Nick Alexeev Feb 24 '13 at 23:22
  • @DavidGiven By the way, which development environment are you using for MSP430? – Nick Alexeev Feb 24 '13 at 23:24
  • mspgcc and mspdebug, although the current project is in assembly. MSP430 assembly is a joy to work in (although it has its usual selection of weirdnesses). – David Given Feb 25 '13 at 00:30