Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
...is there a prescribed way in webbotlib to enable a pull-up resistor.
pin_make_input(B6, TRUE);
I had it walking using my DIY remote control over XBEE.
I've been thinking of making a DIY remote myself, but using EasyRadio . . . is it fancy enough to see?
I would be curious to hear when you get this working. With all the tutorials for interfacing PS2 controllers, i though it would be easy. I tried 3 different libraries and 2 tutorials and could never get it to work. (granted on a arduino not an Axon. )
#define PS2_DAT K4#define PS2_CMD K5#define PS2_SEL K6#define PS2_CLK K7// Define our SPI interfaceSPI_DEVICE PS2_device = MAKE_SPI_DEVICE(SPI_MODE_0,SPI_DATA_ORDER_LSB,PS2_SEL);// Now wrap all the devices into a listSPI_DEVICE_LIST spiBus1[] = {&PS2_device};SPI_SW g_spiPS2 = MAKE_SW_SPI(spiBus1, PS2_CMD, PS2_DAT, PS2_CLK);void PS2_Init(void) { spiInit(&g_spiPS2, TRUE); pin_make_output(PS2_SEL); // init the select pin pin_high(PS2_SEL); // Initialize to high... pin_make_input(PS2_DAT, TRUE); // make the dat line input But also enable pull-up};void _PS2_ShiftOut(unsigned char *pb, int cb){ while (cb) { spiSendByte(&g_spiPS2, *pb++); cb--; }}boolean PS2_Query(unsigned char *paData, int cb){ int iLoopCnt; unsigned char bMode; // Hack to not have this loop forever in case of error for (iLoopCnt = 0; iLoopCnt < 10; iLoopCnt++) { //spiDeviceSelect(PS2_device, TRUE); pin_low(PS2_SEL); // shiftout CMD,CLK,FASTLSBPRE,[$1\8] spiSendByte(&g_spiPS2, 0x1); //shiftin DAT,CLK,FASTLSBPOST,[DS2Mode\8] bMode = spiSendByte(&g_spiPS2, 0x42); if (bMode & 0x70) { // we are in an analog mode so continue to read in the extra bytes. while (cb > 0) { *paData++ = spiSendByte(&g_spiPS2, 0); cb--; } return TRUE; } pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL); // Not initialized properly, try to send out the correct init sequences. pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER static unsigned char _aps2_2a[] = {0x01, 0x43, 0x0, 0x1, 0x0}; _PS2_ShiftOut(_aps2_2a, sizeof(_aps2_2a)); pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK static unsigned char _aps2_3[] = {0x01, 0x44, 0, 1, 3, 0, 0, 0, 0}; _PS2_ShiftOut(_aps2_3, sizeof(_aps2_3)); pin_high(PS2_SEL); clockWaitms(1); //;pin_low(PS2_SEL); //;shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4D\8,$00\8,$00\8,$01\8,$FF\8,$FF\8,$FF\8,$FF\8] ;VIBRATION_ENABLE //;pin_high(PS2_SEL); //;clockWaitms(1); pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE static unsigned char _aps2_4[] = {0x01, 0x4F, 0, 0xff, 0xff, 3, 0, 0, 0}; _PS2_ShiftOut(_aps2_4, sizeof(_aps2_4)); pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE static unsigned char _aps2_5[] = {0x01, 0x43, 0, 0, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a}; _PS2_ShiftOut(_aps2_5, sizeof(_aps2_5)); pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT static unsigned char _aps2_6[] = {0x01, 0x43, 0, 0, 0, 0, 0, 0, 0}; _PS2_ShiftOut(_aps2_6, sizeof(_aps2_6)); pin_high(PS2_SEL); clockWaitms(144); //nap 4 } // If we got here it means that we tried a number of times and it failed, so set up a set of default values and return. paData[0] = 255; paData[1] = 255; paData[2] = 128; paData[3] = 128; paData[4] = 128; paData[5] = 128; return FALSE;}
//=============================================================================// PS2 - controller file//=============================================================================#ifndef _PS2_CONTROLLER_H_#define _PS2_CONTROLLER_H_#define PS2_DAT K4#define PS2_CMD K5#define PS2_SEL K6#define PS2_CLK K7void PS2_Init(void) { pin_make_input(PS2_DAT, TRUE); // make the dat line input But also enable pull-up pin_make_output(PS2_CMD); // Make command pin be output pin_make_output(PS2_SEL); // init the select pin pin_high(PS2_SEL); // Initialize to high... pin_make_output(PS2_CLK); // Make clock be output};// PSx controller communication function.// send a byte on the command line and receive one on the data line.// needs Attention pin to have gone low before called to activate controller.BYTE gameByte(BYTE command){ short int i ; short int j; delay_us(1); short int data = 0x00; // clear data variable to save setting low bits later. for(i=0;i<8;i++) { if (command & 0x1) pin_high(PS2_CMD); //sbi(PORTK, PScommand); // bit bang "command" out on PScommand wire. else pin_low(PS2_CMD); //cbi(PORTK, PScommand); pin_low(PS2_CLK); //cbi(PORTK, PSclock); // CLOCK LOW //delay_us(1); // wait for output to stabilise for (j=10; j > 0; j--) ; if ( pin_is_high(PS2_DAT)) //if((PINK & _BV(PSdata))) sbi(data, i); pin_high(PS2_CLK); //sbi(PORTK, PSclock); // CLOCK HIGH command = command >> 1; } pin_high(PS2_CMD); //sbi(PORTK, PScommand);// delay_us(20); // wait for ACK to pass. for (j=100; j > 0; j--) ; return(data);}void _PS2_ShiftOut(unsigned char *pb, int cb){ while (cb) { gameByte(*pb++); cb--; }}boolean PS2_Query(unsigned char *paData, int cb){ int iLoopCnt; unsigned char bMode; // Hack to not have this loop forever in case of error for (iLoopCnt = 0; iLoopCnt < 10; iLoopCnt++) { //spiDeviceSelect(PS2_device, TRUE); pin_low(PS2_SEL); // shiftout CMD,CLK,FASTLSBPRE,[$1\8] gameByte(0x1); //shiftin DAT,CLK,FASTLSBPOST,[DS2Mode\8] bMode = gameByte(0x42); if ((bMode & 0xf0) == 0x70) { // we are in an analog mode so continue to read in the extra bytes. gameByte(0); // ignore first byte which should return 0x5a while (cb > 0) { *paData++ = gameByte(0); cb--; } // And clear our select line... pin_high(PS2_SEL); return TRUE; } pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL); // Not initialized properly, try to send out the correct init sequences. pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER static unsigned char _aps2_2a[] = {0x01, 0x43, 0x0, 0x1, 0x0}; _PS2_ShiftOut(_aps2_2a, sizeof(_aps2_2a)); pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK static unsigned char _aps2_3[] = {0x01, 0x44, 0, 1, 3, 0, 0, 0, 0}; _PS2_ShiftOut(_aps2_3, sizeof(_aps2_3)); pin_high(PS2_SEL); clockWaitms(1); //;pin_low(PS2_SEL); //;shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4D\8,$00\8,$00\8,$01\8,$FF\8,$FF\8,$FF\8,$FF\8] ;VIBRATION_ENABLE //;pin_high(PS2_SEL); //;clockWaitms(1); //pin_low(PS2_SEL); //shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE //static unsigned char _aps2_4[] = {0x01, 0x4F, 0, 0xff, 0xff, 3, 0, 0, 0}; //_PS2_ShiftOut(_aps2_4, sizeof(_aps2_4)); //pin_high(PS2_SEL); //clockWaitms(1); pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE static unsigned char _aps2_5[] = {0x01, 0x43, 0, 0, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a}; _PS2_ShiftOut(_aps2_5, sizeof(_aps2_5)); pin_high(PS2_SEL);// clockWaitms(1); // pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT//// static unsigned char _aps2_6[] = {0x01, 0x43, 0, 0, 0, 0, 0, 0, 0};// _PS2_ShiftOut(_aps2_6, sizeof(_aps2_6));// pin_high(PS2_SEL); clockWaitms(144); //nap 4 } // If we got here it means that we tried a number of times and it failed, so set up a set of default values and return. paData[0] = 255; paData[1] = 255; paData[2] = 128; paData[3] = 128; paData[4] = 128; paData[5] = 128; return FALSE;}#endif