SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By Holok
#141730
Well in short here is my problem, I'm trying to work with the PS/2 protocol but there is a hick up, I need to use an external interrupt on a pin that also handles output and the data sheet even says it's possible how ever the interrupt also triggers when I use the pin to send data and because of PS/2 protocol I end up in an infinite loop.

Communication works over two pins like this;
Code: Select all
(Both are held high on both ends for idle)

Device (keyboard) -> Host (Computer)
Device clock pin sets communication clock pulse, host reads Data pin on falling edge of clock.
Thats pretty straight forward however 

Host -> Device 
Host lowers clock pin for >100us (priority over any other communication) 
Then Device sets clock pulse and device reads on rising clock.
The problem that gives an infinite loop as the interrupt required for the Host communication init of 100us+ also triggers when I use the clock to pulse when sending data.

Hope I've made it clear enough for people to understand, so how can I do this? One thought I have is turn off that interrupt when not in idel mode and then too poll the state of the clock pin before every time the device lower it as that span is 30-50us and therefor should catch any 100us low, but is there an easier way that I'm missing? some setting to interrupt that can ignore states set by the MCU itself?
By stevech
#141852
Did you consider starting with one of the many existing freeware implementations of the PS/2 protocol? Such as on AVRfreaks.net, projects section? Google will probably find quite a few.

The gist of the approach is to use the hardware timer in a mode that tells you the number of timer cycles since the last state change on the sensed bit (data line).
By Holok
#141911
Thanks, I'll take a look at those libs, mostly been reading PS/2 specifications but the idea is learning so I'm trying to avoid just copy/paste :)

Which mode has that function? if you know? need to take another look at the data sheet cause I've must have missed that and thanks for pointing me in the right direction :)