Page 1 of 1

PS-2 Mouse Interfacing

Posted: Sat Feb 10, 2007 2:02 am
by XCHG
I am trying to interface with a PS-2 mouse device in this test OS and I was wondering if what I am doing is correct. I would appreciate it if somebody could confirm this:

1. I send command 0x20 to the On-board Keyboard controller at port 0x64.
2. Read the Keyboard controller command byte at port 0x60.
3. Enable Bit#1 in the command byte to enable the PS-2 mouse.
4. I sent command 0x60 to the On-board keyboard controller at port 0x64.
5. I then send the modified byte at the 3rd step to port 0x60 to enable the PS-2 mouse.
6. Send the command 0xF5 to port 0x60 to disable mouse’s streaming mode.
7. I then send the command 0xFF to port 0x60 to reset the mouse.
8. Send the command 0xEA to port 0x60 to enable Streaming Mode.
9. Send the command 0xE9 to port 0x60 to ask the mouse to reports its 3-byte status.

The problem is that the mouse seems to be replying with proper acknowledge messages but the status byte reported at the 9th step returns 3 acknowledge bytes (0xFA). Can anybody help me fix this, please?

Posted: Sat Feb 10, 2007 2:29 am
by pcmattman
You have to wait for the mouse to recieve and process the command. If you try to retrieve data before it's ready, you'll get the same data as you read before.

Posted: Sat Feb 10, 2007 2:49 am
by XCHG
I wait for approximately half a second (~500 Milliseconds) after sending and before receiving any data. I will post the code here if I can't fix it. Thank you.

Posted: Sat Feb 10, 2007 3:10 am
by pcmattman
Just a thought - why don't you just loop while you recieve '0xFA'? Then, when you recieve something else, the loop breaks and you can then get the proper data. Of course, you'd only use this for your testing to find out if the mouse is in fact sending you the packet, but then you could also find out how long to wait.

Posted: Sat Feb 10, 2007 6:17 am
by Brendan
Hi,
XCHG wrote:I wait for approximately half a second (~500 Milliseconds) after sending and before receiving any data.
For polling, you need to check the keyboard controller's status register before trying to read data from it's 1 byte keyboard buffer. Most online demo code won't show this (either because they use interrupts like sane people, or they aren't very good) - it's worth downloading one (or more) datasheets like this to get better information...

Also note that most keyboard controller datasheets have an output buffer (for data going out of the controller to the computer) and an input buffer (for data going into the controller from the computer). This seems completely around the wrong way to people like us...


Cheers,

Brendan