Sorry that my previous answer was not sufficient.
As I mentioned in the other posting that when I use the Arc32, I connect the PS2 receiver to the AUX 2 pins. Which is section (E) in the Arc32 data sheet hardware overview, which is P40-43. This is because the DAT line of the PS2 requires a pull-up resistor and these IO lines on the Arc32 has pull-up resistors installed. The J5-AUX2 diagram in the data sheet shows where these pins are. I plug the DAT line (often brown wire of 4 wire group on PS2 connector) into P40. You need to also plug the controller into a +5v (Vcc) and ground. Not sure what PS2 connector you are using, so not sure of colors. But I think yellow may be the current one. The question will be where to get the Vcc. If you have configured your Arc32 that one of the groups of 8 pins has +5v you can use one of these groups. Or you can use pins 7-8 on Aux1 header to get power/gnd. Or you can for example use an exacto knife or the like to remove the power pin from the 2 pin connector and plug it into one of the Vs pins in the a Vcc pin of the Servo power selection jumpers (labeled C on the hardware block diagram) and plug the ground in somewhere convenient like the other pins on the Aux 2 header...
In the Data section of my Basic Program I have the following defines:
Code:
;[PS2 Controller Constants]
PS2DAT con P40 ;PS2 Controller DAT (Brown)
PS2CMD con P41 ;PS2 controller CMD (Orange)
PS2SEL con P42 ;PS2 Controller SEL (Blue)
PS2CLK con P43 ;PS2 Controller CLK (White)
PadMode con $73
As I mentioned in the previous post, I use a slightly striped down PS2 init code that leaves me in the default analog mode, which only returns 6 extra bytes ($73) instead of the code that many of the programs use that returns 18 extra bytes ($79) as most programs don't use the button pressure values returned in the extra bytes.
The code at the start of the PS2 control input for the Phoenix has the following code:
Code:
;--------------------------------------------------------------------
;[Ps2 Controller Variables]
DualShock var Byte(7)
LastButton var Byte(2)
DS2Mode var Byte
PS2Index var byte
#ifdef DEBUG_PS2
DSPrev var byte(7)
fDSChanged var bit
iDS var byte
#endif
;--------------------------------------------------------------------
;[InitController] Initialize the PS2 controller
;--------------------------------------------------------------------
InitController:
;PS2 controller
RetryPs2TestInit:
high PS2CLK
LastButton(0) = 255
LastButton(1) = 255
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$1\8]
shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DS2Mode\8]
high PS2SEL
pause 1
if DS2Mode <> PadMode THEN
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
high PS2SEL
pause 1
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
high PS2SEL
pause 1
#if 0
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
high PS2SEL
pause 1
#endif
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
high PS2SEL
pause 1
#if 0
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
high PS2SEL
#endif
pause 1
sound cSOUND,[100\4000, 100\4500, 100\5000]
goto RetryPs2TestInit ;Check if the remote is initialized correctly
ENDIF
return
;--------------------------------------------------------------------
;[ControlInput] reads the input data from the PS2 controller
;--------------------------------------------------------------------
ControlInput:
; In case the controller gets out of whack double check to see if we are still in the right
high PS2CLK ;init clk state
low PS2SEL
shiftout PS2CMD,PS2CLK,LSBPRE,[$1\8]
shiftin PS2DAT,PS2CLK,LSBPOST,[DS2Mode\8]
high PS2SEL
pause 1
if(DS2Mode <> PadMode)then
gosub RetryPs2TestInit ; use secondary name so does not depend on if XBee is also defined...
endif
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$1\8,$42\8]
shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8, DualShock(2)\8, DualShock(3)\8, |
DualShock(4)\8, DualShock(5)\8, DualShock(6)\8]
high PS2SEL
;pause 10
#ifdef DEBUG_PS2
fDSChanged = 0
for iDS = 0 to 6
if DualShock(iDS) <> DSPrev(iDS) then
DSPrev(iDS) = DualShock(iDS)
fDSChanged = 1
endif
next
if fDSChanged then
hserout ["DS: ", hex dsPrev(0), " ",hex dsPrev(1), " ",hex dsPrev(2), " ",hex dsPrev(3), " ",|
hex dsPrev(4), " ",hex dsPrev(5), " ",hex dsPrev(6), 13]
endif
#endif
The above code has an init function, that you can call at the start. The main function ControlInput reads in the data. It checks to make sure we are still in analog mode and if not will reinit the PS2 controller. There is some debug code here that will print out the PS2 data if any of the data changes. After this code completes the array: DualShock has the current PS2 data.
Also as this is a code extract don't be alarmed if there are variables that are undefined... Like I think I use a sound command to a defined pin like cSound: I often plug in a cheap and dirty radioshack speaker into a pin such that I can get sound... It would be better to hook up a full sound circuit, but I only had one of these speakers fail once with me just connecting it directly up to a signal pin and ground...