help! - serial communication to an ipod, mode4-AiR

I have a 2nd generation iPod nano that I'm trying to control with my arduino.

I'm using the Apple_Accessory_Protocol found on ipodlinux.org:

I can get all the mode 2 commands working, but when i try to send mode 4 commands (after switching to mode 4) I get either no response at all (on some commands) or i get an error response (0x04 0x00 0x01 0x04). which means: 4=you exceeded the limit of whatever you were requesting/wrong parameter-count.

example, if i send: 0xFF, 0x55, 0x03, 0x04, 0x00, 0x1E, 0xDB i get the response: 0xFF, 0x55, 0x06, 0x04, 0x00, 0x01, 0x04, 0x00, 0x1E, 0xD3.

but I have tried this for quite a few commands, either the information on what parameters to send is wrong, or mode4 commands doesn't work on a 2g nano, or somehow I'm sending it wrong.

Does anyone here have any clues to what's wrong?

here is how i connected it and some code.
(signal goes from tx on arduino through 1kohm resistor to rx on ipod and through 2kohm more to ground, pin21 connected to ground with a 500ohm resistor (have tried some different resistors, including 500kohm))
Rx (input 0) --------------------iPod pin12 Tx

Tx (output 1) ---[1k]-------------iPod pin13 Rx
|
| ----iPod pin21 Accessory
| |
| |


2k 500


| |
| |
Gnd-------------------------------iPod pin11 Ground

code in arduino:
byte switchMode4[] = {0xFF, 0x55, 0x03, 0x00, 0x01, 0x04, 0xF8};
byte getPosition4[] = {0xFF, 0x55, 0x03, 0x04, 0x00, 0x1E, 0xDB};

void setup ()
{
Serial.begin(19200);
for (int i=0;i<8;i++){
Serial.print(switchMode4*,BYTE);*
}
}
void loop ()
{
/*for (int i=0;i<7;i++){ // i have experimented with different lengths.
Serial.print(getPosition4*,BYTE);*
}
delay(2000);
}

void loop ()
{
/*for (int i=0;i<7;i++){ // i have experimented with different lengths.
Serial.print(getPosition4[i],BYTE);
}
delay(2000);
}

You have an opening comment symbol there, but no closing comment symbol. The C-style /* and */ comment symbols must match up. They do not care about the end of a line, like the new C++ // coments do.

Does this sketch compile without errors, with a mismatched comment?

Not sure about the protocol here but are your checksums formed correctly?

On this link, do you add the checksum with FF or do you AND it with FF?

http://www.ipodlinux.org/wiki/Apple_Accessory_Protocol

How are you reading the response? Are you leaving enough time for the data to appear on the serial port?

Does not sound like a hardwar eissue f you got a rsponse on the other mode.

thnx for the replies.

I actually just copy pasted a few lines from the code, leaving out the function for listening incomming transmissions, but yes the code does compile.

I have a very simple function for reading the incoming data:

if(Serial.available()>0){
incomming=Serial.read();
if(DEBUG){
Serial.print(incomming);
}
there is a delay(2000) after each command sent, so there is enough time for a response and the reading part works, I can read the error messages that the iPod sends back.

I actually calculate the checksums manually with a calculator, adding the sum of all the bytes after the 0xFF, 0x55 and then subtracting it from 100(hex), so:
{0xFF, 0x55, 0x03, 0x04, 0x00, 0x1E, 0xDB};
would be :3+4+0+1E=25
100-25 = DB.

so no, I'm not AND'ing it with FF, but that's not necessary unless the first part of the equation would be greater then 100, right? (which it isn't). I also used the same method for creating the checksums for all the mode 2 commands that work.

I've been taking a few days off for another project so I haven't done any more experiments, next one is going to be trying it with another iPod and some different commands.

So I'll report back with my results in a few days.