Audi Concert Audio AUX Input

Keep a log of a project build here. Be sure to include pictures and as much documentation as possible.

Audi Concert Audio AUX Input

Postby vtl » January 30th, 2011, 9:46 pm

Audi Concert Audio AUX Input

Image
Audi Concert I, The thing I will be hacking


Background

I wanted a way to add audio input to my vehicle but unfortunately this is quite a difficult proposition. The only audio input comes from the CD changer and the audio inputs are only activated once when the head unit and CD changer communicate with each other and go into the CD mode. This is a proprietary protocol and because the car is an Audi, all the audio adapters for sale are stupidly expensive for what they are. I don’t like paying $70+ for what is just a 30 cent ASIC on a low quality PCB and packaged in a plastic shell, especially in this day and age of epic economies of scale.

Research

After some research it seems people have already accomplished the reverse engineering of the bidirectional protocol between the CD changer and head unit, it is used in almost all Volkswagen AG vehicles. Unfortunately, they did it in PIC assembly language (their project is the open source VWCDPIC project). Assembly is probably the most non-portable language I can think of and I don’t have a PIC programmer. I have an MSP430 Launchpad programmer and a bunch of chips just waiting to be put in a project and I didn’t feel like switching to PICs when I have all these chips sitting around. It would probably take weeks to make sense of it all and the protocol itself isn’t documented; you would have to make sense of what the code is doing, and then port the code. I knew that with this many variables the chances of getting a working prototype in a reasonable amount of time would be small, there would be no way of determining what the problem would originate from, incorrect timing, logic errors, bad wiring, EMI or alignment of the planets!

After a while I was ready to give up but I thought it might be worth Googling some of the hex command codes for the CD changer I had got from the VWCDPIC ASM code. To my surprise, Google provided an AVR C source file code which was ported from the VWCD project. This file seemed fairly complete so I thought it’d be a good basis to start. I have a bunch of msp430 chips but I knew directly porting the code would be troublesome, I wouldn’t be able to determine if the original c code was bad or if my code was bad.

Luckily I have a Seeeduino Mega based on an ATmega1280 MCU. I decided porting the C code to the 1280 to see it working and then porting it to the MSP430 would be the route I would go down. The C code target was an ATmega128 microcontroller which unfortunately many of the registers have different names and the relevant bits are in different places.

Hardware

Obviously the micro has to plug into the head unit somehow. Most interfaces I had seen are housed in a little plastic box and plug into the head unit on the back. Annoyingly because this is a German vehicle, these plugs are quite expensive. I took apart the headunit and poke around. I saw that the sockets that accept the audio and power harnesses are soldered with through-hole pins that are visible on the underside of the headunit.


Image
The black sockets accept the various wiring harnesses (power, CANBUS, speakers, CD changer)

I figure it will be pretty easy to just probe to see which pins correspond to what pin on the socket. I soldered in wires for the DATAIN DATAOUT and CLOCK for the bidirectional communication, +12v power and ground, and the audio inputs. While people might be scared off by soldering, it really wasn’t hard. I used some telephone wire, held it in position with some Blu-tack and just heated the joint. If you also put a dab of flux, the wire pretty much moves itself into place. If you were wondering why the insulation runs so close to the point of soldering, I stretched the insulation with my fingers so the exposed wire would be covered. I have also disconnected the CD changer.

Image
Pins were probed and the required pins were soldered


Since I had recently taken apart a VCR, I thought maybe the tape player in this head unit was similar. In a VCR the entire metal housing for all the motors and mechanisms come out in a neat packaged unit and plug in into the main PCB without having to desolder anything. This head unit was exactly the same, the tape deck disconnects with 2 plugs and the whole thing is removed by unscrewing 4 Torx screws.


Image
The discarded tape player module. When removed, the CD changer does not seem to notice it is missing.

This made the head unit almost like an empty box, perfect for housing the entire project. You could even fit a HDD based mp3 player in there if you wanted, the possibilities are endless. To develop and test my solution, I took out the headunit and powered it with a bench supply with alligator clips. This was certainly much better than sitting in the car all day in hot weather programming it on a laptop.

Back to software

I went back to porting the code for the 1280, I just used the Arduino IDE, it’s fairly terrible for this much code but I seemed to manage. I just went with a main() method and didn’t go with the conventional setup() and loop() routines you might be familiar with. After correcting some logical errors I seemed to get it working with my head unit fairly quickly. Once the board was hooked up the head unit would go into the CD mode and the audio inputs would activate! It worked pretty much first go which was nice. Looking through the code, it seems there is still a ton of unnecessary code like disabling interrupts, remnant code from his port from the PIC ASM. While I had it working, I didn’t want to sacrifice a Mega board because it is way too expensive to be wasted permanently housed in my head unit. Next step was to now port it to an MSP430, I can develop with the Launchpad board and take out the chip and put it into my own PCB when it is working.
Having learnt a ton from porting the C code doing the msp430 would now be possible.


Protocol

The protocol is actually two uni directional links using 2 different methods of communication. This is only a brief description and only covers the important features of the protocol. However, this information should make it infinitely easier than digging around and figuring it out from scratch.

DATAOUT:
The DATAOUT pin that communicates from the headunit to the CD changer is a 1-wire asynchronous serial (but not standard UART) communication that depends on the timing of the low periods to determine start, high or low bits.

According to VWCDPIC, the low period of this line:
0: ~650us //represents logic 0
1: ~1.77ms //represents logic 1
S: ~4.57ms //the start bit signifying the start of a 32bit packet

Each of the command codes has the following format:
Byte 1: 53 //first header byte
Byte 2: 2C //second header byte
Byte 3: //data byte
Byte 4: //data byte/error detection

First two bytes are always 53 and 2C and are the header bytes
Last two bytes are the command codes. Both of these codes always add up to 0xFF so the fourth byte can effectively be considered only for error detection.

DATAIN and CLOCK:
This pin is what the CD changer uses to send data to the head unit. It sends acknowledgement of data commands sent by the CD changer and also sends CD information like CD number and track number.
This data pin is clocked by the clock pin. The clock is normally high and only clocks when there is data to transmit, similar to SPI. The clock period when data is being transmitted is 7.5us low, 7.5us high. Each data message is made up of 8bytes (32bit). While transmitting, there is 700us pause between each byte. Furthermore, these 32bit messages is transmitted every 50ms or so.

To implement this protocol, timers are used to trigger interrupts that will run at the correct intervals. The MSP430G2231 I am using for this only has 1 timer and a watchdog timer so I will have to use software delays to implement some of the timing. For DATAOUT, the TimerA is used in capture mode on a pin, when a transition is detected, the timer will be triggered and start counting. When it is triggered again, the low pulse time is then recorded to determine if it was a 0, 1 or start bit. For data out, the 700us period is done with the watchdog timer and the rest of the timing is done by software delays. The default clock frequency for the MSP430G2231 is 1MHz so many of the timing periods had to be adjusted. Finer details can be seen from the code itself.

Prototype

Unfortunately the crappy 14pin Launchpad chips only come with 2KB of memory which is really limiting. I managed to squeeze most of the protocol functionality in but there’s less than 50bytes of flash left, there’s no serial debugging output and not much space left if I wanted to pass on the head unit button commands to an mp3 player (e.g. iPod or iPhone). If you want the good MSP chips you really have to go surface mount, a qfp64 or qfp80 is what I might want to try later. Texas Instruments has got the 8kb 20pin dip chips on the way so they’re an option too.
Porting to the msp430 chip wasn’t too difficult once the timing differences were worked out and now all I had to do was to create a custom board that would convert 12v from the headunit into the 1.8-3.6 required by the micro. I had recently desoldered a ton of transistors, ICs and resistors from an old VCR and scored a TL431 voltage reference IC so I decided to go with that. Instead of using two precision resistors for the voltage divider, I went with a 100k potentiometer with the wiper connected to the ref pin so I could calibrate the output voltage to 3.6v with a multimeter.


Image
A simple regulator circuit from the Texas Instruments TL431 datasheet

I found the performance of this to be quite terrible without smoothing capacitors; the output would appear stable at first but vary quite wildly later if the circuit had been running for a while (nothing was even close to overheating). I put a 1uF capacitor on the output and it appears to work ok.
I soldered the simple circuit on some scrap protoboard and screwed in a copper standoff in a convenient vacant hole in the head unit PCB. It doesn’t look pretty but it is functional. Since the thing is housed inside of the head unit looks don’t matter anyway. If I had the means to produce my own PCBs I would’ve done that, but low cost was certainly a priority on this project. The total cost of components was almost $0 for this project; everything except the MCU was spare salvage components.


Image
The completed prototype. Board is held in securely with a screw an ATX brass standoff.

The next step is to load the code onto a better msp430 and pass on the head unit button presses to control a connected mp3 player. With the code and documentation I have posted, pretty much anyone can modify it to suit their needs.

Links:
VWCDPIC Project: http://www.k9spud.com/vwcdpic/
Incomplete C code I discovered for ATMega128: http://www.mikrocontroller.net/attachment/31279/vwcdc.c

My ported code is attached. When interfaced to the CD changer, pressing the buttons in CD mode will successfully update the head unit's display and the audio inputs are enabled. It should be a simple task to interface this to an mp3 player.

This is still beta quality software with bugs, pressing and holding fast forward will cause the headunit to spam the fast forward command code, the software is not going into the mode that the head unit is expecting so it keeps repeating. The MSP port is less robust than the avr code so keep that in mind.

The MSP zip is a code composer studio project. If you don't like code composer then just copy the source files out.

The ATmega1280 is an arduino sketch, please bear in mind the official Arduino Mega does not have PortD pins broken out for you and won't be compatible. Port D was required for Timer capture and compare.
Attachments
vwcdc_msp430_CCS_Project.zip
(38.36 KiB) Downloaded 1196 times
vwcdc_atmega1280.zip
(11.26 KiB) Downloaded 1071 times
Last edited by vtl on February 6th, 2011, 5:20 am, edited 1 time in total.
vtl
 
Posts: 30
Joined: January 27th, 2011, 9:18 am
Location: Melbourne, Australia

Re: Audi Concert Audio AUX Input

Postby futaris » January 31st, 2011, 2:56 am

Thanks for the detail on the CD Changer Protocol. This is the protocol used in B5, B6 and B7 Audi A4s i.e. Generation I, Generation II and Generation II+ Audi head units.

Note that on a Generation II+ (Chorus II+, Concert II+, Symphony II+) Audi Head Unit, Aux In also available on the Quadlock connector. However, it should also be possible to hack into the internal MP3 / CD Changer, and display text... See the below thread

http://www.mp3car.com/vbulletin/hardwar ... -post.html
futaris
 
Posts: 1
Joined: January 31st, 2011, 2:50 am
Location: Brisbane, Australia

Re: Audi Concert Audio AUX Input

Postby Wolfin » February 3rd, 2011, 5:04 pm

Very well done! Even without access to expensive parts, you pulled off a professional hack. I love when people add auxiliary input to car stereos, as they're notoriously proprietary - getting them open and useful is always impressive.
User avatar
Wolfin
 
Posts: 9
Joined: January 27th, 2011, 4:50 pm

Re: Audi Concert Audio AUX Input

Postby vtl » February 4th, 2011, 8:11 pm

Thanks, was a nice feeling making this thing entirely out of junkbox parts and not needing any expensive tools like a logic analyzer or scope.
vtl
 
Posts: 30
Joined: January 27th, 2011, 9:18 am
Location: Melbourne, Australia

Re: Audi Concert Audio AUX Input

Postby iToast » February 5th, 2011, 8:05 am

Pff, now make it use a msp430 to make a virtual cd changer with a internal sd card holding the music, then make it work with the lcd screen.
iToast
 
Posts: 115
Joined: January 27th, 2011, 10:24 am

Re: Audi Concert Audio AUX Input

Postby geebles » August 30th, 2012, 11:49 am

Hi! This is exactly what I would like to do to my Audi stereo (I have the same version but with a CD player, i think its a Concert II) .. Either way it has the same connection and interface.

I only have an Arduino Uno, but have fairly good knowledge of programming, just not with AVR studio etc.. only Arduino.. how hard would it be to have this in Uno/Arduino code? I've seen your source file and I cannot get it to compile for Uno..

Can you please explain how the protocol works a little more clearly?

So is clock at gnd, but when it is high is when data is being received/sent? I'm looking for the moment to get my head around that and write a small sketch to read the inputs.. just trying to work out the logic of it.. would be very much appreciated if you have the time to explain it to me or point me to somewhere that explains it (not necessarily for the CDC port but a similar protocol that would relate)

I am very jealous of your creation and would like to build one myself :)

Is there a particular 'response' that the stereo is looking for to enable the CDC jack? like an 'Enable' or something? because when i try mine with NOTHING plugged into the CDC port it says "NO CDC" so i'm assuming the 2 way communication is looking for something..

Regards Giles
geebles
 
Posts: 6
Joined: August 30th, 2012, 11:40 am
Location: Bristol

Re: Audi Concert Audio AUX Input

Postby Knack » October 9th, 2012, 1:28 pm

I did this the analog way by just intercepting the audio from the cd changer to the head unit in my MK1 TT. Now that I see that removing the tape player does not cause any issues with functionality, I want to try putting my DealExtreme bluetooth receiver in there so that I can connect from my phone straight to the head unit to stream audio.

I also have a few 430's floating around needing a project so I'll take a look at that code ( be warned, I'm a total n00b at programming) and see what I can break.

Chris
User avatar
Knack
 
Posts: 7
Joined: January 27th, 2011, 7:27 pm
Location: Willis, Texas

Re: Audi Concert Audio AUX Input

Postby trigano » February 26th, 2013, 4:05 pm

This is just what I've been looking for (for weeks) - have an MSP430 Launchpad waiting for this project. Worked out some of the timings, nice to see that I was on the right route. There are commercial solutions out there but I can't bring myself to pay for something I should be able to make myself...

Does anyone know where the code might be/have the code (for the MSP430 and ATMega), the links above don't work any more, I'd prefer not to have to recreate it from the vwcdc.c code.

Thanks
Mark
trigano
 
Posts: 1
Joined: February 26th, 2013, 2:00 pm
Location: Hampshire, UK

Re: Audi Concert Audio AUX Input

Postby Oldsirhippy » June 10th, 2014, 8:38 am

The C code for the AVR may be found here:

http://www.mikrocontroller.net/attachment/31279/vwcdc.c

There is quite a lot of it! :o
Oldsirhippy
 
Posts: 1
Joined: June 10th, 2014, 8:34 am


Return to Project Logs

Who is online

Users browsing this forum: No registered users and 2 guests