Dreamcast Controller Interface: Help requested.

To all, the post following this will be a request for help in interfacing a Dreamcast Controller with an Arduino. I can't attach links, etc.. to my very first post... so this should hopefully let me get around that :slight_smile:

To all,

I'm attempting to interface a Dreamcast Controller with the Arduino Mega and not having much luck. I've gotten all the details of the protocol and the wiring from Marcus Comstedt's website: Dreamcast Programming
Specifically the wire protocol from here: Dreamcast Programming - Maple Bus Wire Protocol and an example of an interface to USB here: Dreamcast Programming - Maple Bus to USB Adaptor

Now, I've been warned that the Dreamcast communicates very differently to most other console controllers. The controllers send data in bursts at 2mbps containing 4 bytes plus other details. Even better is that there are two bidirectional data pins which take turns in being the data or clock.

Both pins High means that the bus is free and controllers wont talk unless spoken to.

To get a controller to talk you must first send the sync packet, then 4 bytes of data, then a checksum and then a little EOM packet.

The basic idea is in my code (heavy duplication in order to work out timing) and then the image shown here:
Timing diagram is here... it's huge.
This is what I would like to see on an oscilloscope on both of my pins, but I've no method of accessing one.

So, my first request is: Does anyone have an oscilloscope, an Arduino and time to upload my code and see what it produces? I've been told that the waveform must be as close to square as possible otherwise the Controllers wont see it.

My code is here (PDE format from Arduino). It's hideous because I wrote each instruction to attempt to tinker with timing, but I could not get any action in the end. You can also see that I've tried a few methods to access pins, expecting speed gains, but I really can't tell anything in the end as I've only really got serial output back to the PC which kills all timing.

Anyway, Any help would be greatly appreciated, or even advice on how to really tackle this problem.

Thanks, Steven.

It's certainly an interesting project. I am quite busy right now, but might be able to test it out this weekend. The scope I have has no ability to transmit waveforms to a PC, so a picture of the CRT would be the best I could manage.

Getting squared waves shouldn't be an issue because that is primary a function of the capacitance of a cable.

kenster,

Thanks for the reply... I had almost given up on this, but might attempt some research on doing faster bitwrites/reads. I'm still entirely concerned that the response from the controller will come so fast that I wont see it.

Do you also have a controller to work with?

Hey kenster, I did this on an atmeg168. I dont use Arduino but you could I would think. The best way is to use a 16 mhz but I had to pull it off with a 12mhz. The only draw back is it only works with the oem DC controller. Just so happens the patents was wrong and its was 9 clocks from bit to bit not 6 :wink:

It is funny because do to the patent madcatz useds a 6 clock, thus I cant read that fast. If you design on a 16mhz you will be able to read the madcatz.

I did it all in asm as timing was so tight, but it does work.. If you are interested at some point give me a shout.

ulao,

I would really like to get your help on this... I've been tinkering with all sorts of other components and it's time to get the Dreamcast controllers working.

Are you able to explain the method you used or, even better, provide source code? Any help is appreciated!

Hi there, I have a controller interface working for an atmega328. Code and some info here:

http://code.lardcave.net/entries/2010/10/19/032116/

It's very rough code, but feel free to ask me questions...

WzDD,
This is awesome news... I haven't written raw ASM for such a long time though, the code scares me.
Time is limited, but I'd love to get my controller working, so thanks again.

Do you see this ever making it to a library for use inside the Arduino IDE? Being a lame Windows user, I've never had to deal with avrgcc directly.. either way, I'll see what happens tinkering around sometime soon.

Steven.

That's a good idea (the Arduino library). I'll have a look at doing that.

WzDD,
I've finally had some time to get a look into your code and tried to get my Densha-De-Go controller working.

I am running on Windows XP, So I've installed WinAVR (latest) and Python 2.6.6 (3.x+ would not compile your code...)
I am also using the Arduino Mega, so your PORTB 0 and 1 weren't usable and I changed this to PORTB 4 and 5 (PWM pins 10 and 11)

I edited your makefile and got the code onto the Arduino... it seems to be communicating. I then run the Python code and it connects and then states that nothing is connected... couldn't find device at 0x20.

I used this document http://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0 to work out what pins I should be using, but I'm not sure I am allowed to use them?

I adjusted the setup() to make sure that 10 and 11 are now INPUT pinmode.

I didn't adjust maskmaple1 or maskmaple5 as they aren't used in the code?

Are there any pointers you can give me regarding the use of this code on an Arduino Mega? Is PINB or SEGR different as well?

Thanks, Steven.

Hi Steven. Nice work getting the code even running. :slight_smile: I don't know anything about the Mega unfortunately. What exactly are you connecting up here? It looks like the Densha-Do-Go controller acts like any other controller to the DreamCast -- so I guess it's just a matter of getting the four wires (power, gnd, clk/data1 and clk/data2) hooked up, like a regular controller?

It kind of looks like you can use those pins. Can you read from them and write to them from a sketch (ie print what digitalread reports when you have the pin at +Vcc and again when it's at gnd -- then hook up a led to one of them via a resistor and run a flasher sketch for that pin)?

Things to try in increasing order of difficulty: swap the two wires around, try different pins, connect up a logic analyser or oscilloscope to the data lines and see if "the lights are on".

Best of luck, let me know what works / doesn't work. :slight_smile:

I actually don't think I'm compiling the code properly anymore...

I tried a delay/digitalwrite to pin 13 in setup() and the LED on 13 would not flash... on a very basic Arduino sketch it does flash. But then your code seems to think it's connecting!? I'll hack further...

It does seem like a logic analyser is the way to go. I'll have to look in to the one you've mentioned in your blog post.

Double-post-yada-yada... :slight_smile:

It seems that I had not set both CPU types and had compiled the Arduino libraries with the 328 instead of 1280. I'd then set both, but not cleaned the whole lot... after removing the Arduino .o's in the build dir and then rebuilding it all my LED started flashing!!

So then... I re-confirmed all the Pythong and ran it.... 'could not find 0x20'... I nearly cried... but then:

connecting to COM3:
connected
No device found at address:
0x20
1c20000501000000ff0f3f000000c800c800000000415400ff204f544920313030746e6f436c6c6f722020726520202020202020206516f725064656375207942205520726f7265646e63694c2065736e656f7246204553206d452041475244544f94d25494130b14d1480b911508080808007d0037178 119
Command 5 sender 0 recipient 20 length 1c
Device information:
Functions  : CONTROLLER
Periph 1   : 0x3f0fff
Periph 2   : 0xc80000
Periph 3   : 0xc8
Name       : .TA.TO .01 Iont0ollCr  r   e    
License    : ..e VF.%..R7.R."V&.&.6.F6W..$.V.2U.b.R..E$u.%M.D.0AI...M..P.
Power      : 2000
Power max  : 32896
Play with the controller. Hit ctrl-c when done.
Command 8 sender 0 recipient 20 length 3
Ltrig 255 Rtrig 255 Joy X 0 Joy Y 0 Joy X2 255 Joy Y2 255 DOWN, LEFT, RIGHT, Y, X
Command 8 sender 0 recipient 20 length 3
Ltrig 255 Rtrig 255 Joy X 0 Joy Y 0 Joy X2 255 Joy Y2 255 DOWN, LEFT, RIGHT, Y, X
Command 8 sender 0 recipient 20 length 3
Ltrig 255 Rtrig 255 Joy X 0 Joy Y 0 Joy X2 255 Joy Y2 255 DOWN, LEFT, RIGHT, Y, X
Command 8 sender 0 recipient 20 length 3
Ltrig 255 Rtrig 255 Joy X 0 Joy Y 0 Joy X2 255 Joy Y2 255 DOWN, LEFT, RIGHT, Y, X

Seems to be a few endian or byte->ascii issues... but otherwise... YEY!

Actually, would these be timing issues? Otherwise the buttons work fine.

Thanks again!

Hi there. Great work so far! There are lots of possibilities here (unfortunately). One is that it could be a timing issue. The other is that it could be related to power. I really don't know much about electronics (I'm a software guy!) so I just poked around until I got the hardware side working. I did notice while I was playing around that 5v seemed more reliable than 3.3v, but since 3.3v is the actual specified voltage I wouldn't recommend this. Eventually I got everything working at 3.3v -- so perhaps what I was doing beforehand was slightly overclocking the hardware to avoid what was really a timing issue?

Running at 3.3v didn't change too much... but spacing out the bit reading in maple_rx_raw with delayquarter(s) has proven to be reliable.

I can now get consistent text, etc from the device...

I'm curious over the first bit/endian issues. My device string comes across with two full stops in front of it (".. TAITO" .. etc) and I'm wondering if they are meant to be there. I ask this, because I cannot see the "B" buttton being pressed on this controller.

Now, since it's the B button, it might be significant, if it's the first bit to be sent across the wire? I don't know if B comes first, etc... I'm about to go and read up on it again at Marcus' site.

I am also going to get a standard controller from home in a few weeks and then test out the complete communications. I'll also post a blog article shortly once I have this controller controlling my model railway n:)

Ah, that's fantastic! Great job. It kind of sucks that you had to add the delays though, because that means it will probably be too slow to work with a regular controller. I wonder if there are enough spare cycles to make it work reliably with both?

Just FYI, I got the same two characters before the device ID on a regular Sega controller as well. So either the layout on Marcus' site is slightly off or (more likely) my implementation of it is...

The B and C buttons do come first (actually I think B is in fact first due to endian swapping), but I do know I've managed to read all the buttons from a regular controller.

I gave up on working out the B button... will get back to that at a later date...

For now, the throttle is controlling my model railway :slight_smile: It's actually good fun... I've added in a very simple acceleration/momentum code and trying to get it to stop at the station isn't easy. Now to code the brake lever...

Blog post is here...

Anyone good with locomotive physics? :slight_smile: