Playstation controller interfacing
Playstation controller interfacing
Anyone had any luck in communicating with an dualshock psx controller. I`ve read somewhere that they use SPI mode 3 for communication but I can´t get it to work. I´m using a PIC18F452 at 10Mhz.
Can you maybe post the code ?
I think here are people that will find it usefull some or other time
I think here are people that will find it usefull some or other time
Another proud user of LV 24-33A Development System and mikroPascal PRO for dsPIC :)
PortA not working? Add CMCON := 7; PortD not working? Add ADCON1 := 6;
To paste code on the forum, please use the [b] Code [/b] button !! ;)
PortA not working? Add CMCON := 7; PortD not working? Add ADCON1 := 6;
To paste code on the forum, please use the [b] Code [/b] button !! ;)
Code: Select all
unsigned short Dp; //Variable for SLCT, JOYR, JOYL, STRT, UP, RGHT, DOWN, LEFT
unsigned short Bt; //Variable for L2 , R2 , L1 , R1 , /\ , O , X , |_|
unsigned short LRAR; //Variable for Right Joy 0x00 = Left 0xFF = Right
unsigned short UDAR; //Variable for Right Joy 0x00 = Up 0xFF = Down
unsigned short LRAL; //Variable for Left Joy 0x00 = Left 0xFF = Right
unsigned short UDAL; //Variable for Left Joy 0x00 = Up 0xFF = Down
char temp;
char tp;
void ACK()
{
while(PORTD.F1 == 0); // Wait for ack from PAD
}
void main()
{
ADCON1 = 0x02; // Setup (VREF, VREF AN0-AN4)
TMR2 = 0;
T2CON = 0xFC;
PIE1.TMR2IE = 1; // enable interupt
INTCON = 0xC0; // for tmr2
PR2 = 0x04;
TRISD = 0x02; // PORTD is input
Spi_Init_Advanced(MASTER_TMR2, DATA_SAMPLE_END, CLK_IDLE_HIGH, HIGH_2_LOW);
tp = 0;
PORTD.F0 = 1;
Delay_ms(1);
while(1)
{
PORTD.F0 = 0; //Enable PSX PAD
Delay_us(10);
tp = Spi_Read(0x80); //Send device check commmand
ACK();
tp = Spi_Read(0x42); //Read ID from device
ACK();
if(tp == 0x82) //If digital mode
{
temp = 0;
tp = Spi_Read(0); //Read "here comes data command from device"
ACK();
Dp = Spi_Read(0); //Read data from device
ACK();
Bt = Spi_Read(0); //Read data from device
ACK();
PORTD.F0 = 1;
}
if(tp == 0xCE) //If analog mode
{
temp = 1;
tp = Spi_Read(0); //Read "here comes data command from device"
ACK();
Dp = Spi_Read(0); //Read data from device
ACK();
Bt = Spi_Read(0); //Read data from device
ACK();
LRAR = Spi_Read(0); //Read data from device
ACK();
UDAR = Spi_Read(0); //Read data from device
ACK();
LRAL = Spi_Read(0); //Read data from device
ACK();
UDAL = Spi_Read(0); //Read data from device
ACK();
PORTD.F0 = 1; //Disable
}
Delay_ms(5);
}
}//~!
Here is the code that I used to interface a PSX controller via SPI interface. It works almost fine, except I get some glitches on the oscilloscope, and I cant figure out why. I hope somebody can try and use this code and maybe refine it a little.