Computing > Embedded Computing

Problem reading Ps2 keyboard arduino


1. I am using arduino mega, and arduino 1.8.8. Code is compied using O3 optimization. I have changes Os to O3 in platform.txt at 3 places for fast code.

2. I have foloowing features enabled in arduino:
a) code send data serial through usb port available on mega  i.e. Serial0  at 9600 baud rate and also used to burn code via arduino software
b) code reads data serially through a device, only rx pin is used, tx not connected. Serial2 at 2400 baud rate
c) Lcd 20x4. : standard arduino library
d) I2C based rtc ds1307 :
e) Internal eeprom to read & store data
f) serial port used to trasmit data , only tx is used, rx unconnected. Serial3 at 9600 baud.
g) Timer 3 at period interrupt of 20ms to scan 4 keys connected at pins.
h) A ps2 keyboard :

3. Problem is when i start the code, i read nothing from PS2 keyboard even if I press the keys on ps2 keyboard. If I keep on pressing some ps2 keyboard for around 10sec, then keyboard start working fine.

4. If i disable everything in code except ps2 library, then code works fine.

5. in complete code, i dont see anywhere i disable keyboard lib.

6. what i suspect, is that i have too many serial interrupt on rx pin, that may be causing issue, as it may interrupt the ps2 code. I dont read serial interrupt actually, as I read on sequentially in mainloop code. where to disable serial interrupt?

7. if not, what else could be issue

Not sure how to help, but I'm fairly each key press produces two events.  A key down and a key up.  You might be seeing something related to that.

I realised, it works fine in below case:
1. When i power up system, without connecting PS2 keyboard, and then connect PS2 keyboard i,e after power up, then it works, all three led on keyboard blinks and it works fine.

2. Whereas when i power up the system with ps2 keyboard connceted, then keyboard dont work. If then i keep pressing some key, after sometime all three led blink & then keyboard works. But i have to press key for more than 15-20sec

When do you initialise the PS/2 interface? Are there pull-up resistors on the PS/2 lines? Is there a chance the microcontroller pulls the clock line low? (Putting the keyboard into "communication inhibited" mode)

Also, on what voltage are you running? Be aware the PS/2 interface is a 5 Volt interface. Running it 3v3 might cause an issue that a "high" is misinterpreted as a "low". Furthermore, saying it starts working after 20 sec, might there be a large capacitor charging up on the supply for the keyboard or its pull up resistors?


[0] Message Index

There was an error while thanking
Go to full version