Interfacing gamecube controller

Have you got the greatest 48 bit multiplier ever conceived? Prove it - post your code here.

Moderator: phalanx

Post Reply
kame
Posts: 3
Joined: Sat Feb 20, 2010 11:50 am

Interfacing gamecube controller

Post by kame » Wed Apr 21, 2010 9:25 am

I'm kind of new to micro controllers, so I came here for some help. Anyway I'm trying to interface the gc pad by making it rumble first but I can't get it working. According to this site:
http://www.int03.co.uk/crema/hardware/g ... ontrol.htm
The gc pad communicates serially with the console using a bi-directional data line, high bits counts as 1us low and 3us high, and low bit as 3us low and 1us high. I'm trying to send 0100 0000 0000 0011 0000 0011 plus 1 stop bit to the controller to make it rumble but since I'm a newbie, I almost have no idea what should I do because I never worked with anything serial before. I tried experimenting and wrote my own code:

Code: Select all

	list p=18f2550

	; Include file, change directory if needed
	include <p18f2550.inc>
    CONFIG FOSC = HS
    CONFIG WDT  = OFF
    CONFIG MCLRE = ON
    CONFIG LVP = OFF

	code	0x000
	
    clrf	TRISA		;RA0 output
    clrf    PORTA
    Reg_1 set 0Ah
    Reg_2 set 0Bh
    

main ;send 0100 0000 0000 0011 0000 0011 + 1 stop bit
call slow
call shigh
call slow
call slow

call slow
call slow
call slow
call slow

call slow
call slow
call slow
call slow

call slow
call slow
call shigh
call shigh

call slow
call slow
call slow
call slow

call slow
call slow
call shigh
call shigh
call shigh
bsf TRISA,RA0
call delay3
bcf TRISA,RA0
goto main





slow  ;GC low
bcf PORTA,RA0
call delay1
bsf PORTA,RA0
return

shigh ;GC high
bcf PORTA,RA0
nop
nop
nop
nop
bsf PORTA,RA0
call delay2
return




delay1:  ;14 instruction delay
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
return

delay2: ;10 instruction delay
nop
nop
nop
nop
nop
nop
return

delay3 ;1 ms delay
 movlw       .125
 movwf       Reg_1
 movlw       .7
 movwf       Reg_2
 decfsz      Reg_1
 bra         $-2
 decfsz      Reg_2
 bra         $-6
return

end


Can anyone help me? By the way I'm using a 20 MHz crystal.

nosesquid
Posts: 2
Joined: Sun Jan 16, 2011 11:43 pm

Re: Interfacing gamecube controller

Post by nosesquid » Tue Jan 25, 2011 4:25 pm

kame wrote: main ;send 0100 0000 0000 0011 0000 0011 + 1 stop bit
call slow
call shigh
call slow
call slow

etc....

bsf TRISA,RA0
call delay3 ; only 1ms
bcf TRISA,RA0
goto main


slow ;GC low
bcf PORTA,RA0 ; .6us after slow is called
call delay1
bsf PORTA,RA0 ; 3us after bcf
return ; another .4 us

shigh ;GC high
bcf PORTA,RA0 ; .6 us after shigh is called, making 1us from an slow call, 3us from shigh
nop
nop
nop
nop
bsf PORTA,RA0 ; 1us
call delay2
return ; 2.4us


delay1: ;14 instruction delay = 2.8 ms (the 14 instructions includes jumping to and from here)

delay2: ;10 instruction delay = 2 us

delay3 ;1 ms delay
[/code]

Can anyone help me? By the way I'm using a 20 MHz crystal.
The code looks fine to the (limited) extent of my knowledge. It's possible there's some kind of additional setup routine you need, hopefully someone else can answer that definitively.
There are a couple of minor differences from the documentation on the website you linked: although the whole conversation takes less than 1ms (so delay3 should be plenty), in the real world, the controller is only polled every 6ms, and the sample code has an even longer 20ms delay.
There's also a different value used to switch the rumble on and off - it's probably optional, but you could give it a shot:
* 0x400300 = value given in YAGCD to initialise pads
* 0x400302 = value seen when i 'scoped the pad in rogue leader
* 0x400001 = rumble motor on?
* 0x400000 = rumble motor off?
Lastly, if you have access to an oscilloscope, you could take a look at what you're actually sending. Failing that, you could try coding up the receiving side, flashing it to another microcontroller, and seeing if you can read anything from the first one.

Post Reply