Propeller to Ipod Communication
Luis_P
Posts: 246
I use the BS2 to control the ipod and works fine. I tried with the Propeller and is not working. What I'm doing wrong?
with the Bs2 I use this code to play: SEROUT 1,$4054,2,[255,85,3,2,0,1,250]
Mike gave me some help to traslate to Spin but no luck!
this is the code:
OBJ
BS2 : "BS2_Functions" ' Create BS2 Object
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 8_000_000 ' External oscillator = 8 MHz
PUB Start ' Main method
repeat ' Endless loop
if ina[23] == 1 ' If pushbutton pressed
BS2.Start(31,30)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 255,9600,BS2#Inv,8) ' Play
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 85,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 3,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 2,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 0,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 1,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 250,9600,BS2#Inv,8)
BS2.PAUSE(2)
else ' If pushbutton not pressed
waitcnt(clkfreq / 20 + cnt) ' Wait 1/20 second -> 10 Hz
with the Bs2 I use this code to play: SEROUT 1,$4054,2,[255,85,3,2,0,1,250]
Mike gave me some help to traslate to Spin but no luck!
this is the code:
OBJ
BS2 : "BS2_Functions" ' Create BS2 Object
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 8_000_000 ' External oscillator = 8 MHz
PUB Start ' Main method
repeat ' Endless loop
if ina[23] == 1 ' If pushbutton pressed
BS2.Start(31,30)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 255,9600,BS2#Inv,8) ' Play
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 85,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 3,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 2,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 0,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 1,9600,BS2#Inv,8)
BS2.PAUSE(2)
BS2.SEROUT_CHAR(1, 250,9600,BS2#Inv,8)
BS2.PAUSE(2)
else ' If pushbutton not pressed
waitcnt(clkfreq / 20 + cnt) ' Wait 1/20 second -> 10 Hz
Comments
Mike what is a PLL multiplier like 8 (PLL8X) ? that refers to the crystal as well? or is another component attached to the chip?
I forgot to post the connections but I think evething is correct because I did on the Bs2.
pin 13 of Ipod to P0 (propeller)
pin 12 of Ipod to P1 (propeller)
pin 11 of Ipod to GND
pin 21 to a 500K resistor to GND.
Any ideas?
I'm using the crystal 8Mhz with:
CON
_clkmode = xtal1 + pll8x ' Feedback and PLL multiplier
_xinfreq = 8_000_000 ' External oscillator = 8 MHz
The connections to the ipod are very simple I don't think there is any problem Pin 13 on the ipod received so I connected to P1 on the Propeller and P12 transmit so I connected to P0 on propeller.
I attache a screen shot of my code, I'm missing something?
How do I use the FullDuplexSerial? Any example I can use?
Gracias.
You'll call start method with your RX and TX pins, some setup, and the baud rate. After that it's really easy. The best thing to do is declare it as an object and then open it to read the notes. If you would post your original BS2 source I'm sure that many of us could help you translate it to Spin.
Based on what's been posted, I think the start method will look something like this:
Note that iRX is FROM the iPod, iTX is TO the iPod (sometimes those connections are confusing). The %1100 inverts RX and TX. Obviously, the last parameter is the baud rate. After you've started the object use the .tx() and .str() methods to send commands.
SEROUT 1,$4054,2,[255,85,3,2,0,1,250]
Can you help me to traslate, jonny? I'm new on the propeller so I don't know how to create a method.
Gracias!
Code:
CON
_clkmode = xtal1 + pll8x ' Feedback and PLL multiplier
_xinfreq = 8_000_000 ' External oscillator = 8 MHz
OBJ
Ipod: "FullDuplexSerial"
Pub SendCommands
Ipod.Start (0, 1, %1100, 9600)
Ipod.str(string ("255"))
waitcnt (clkfreq*2 + cnt) 'pause
Ipod.str(string ("85"))
waitcnt (clkfreq*2 + cnt) 'pause
Ipod.str(string ("3"))
waitcnt (clkfreq*2 + cnt) 'pause
Ipod.str(string ("2"))
waitcnt (clkfreq*2 + cnt) 'pause
Ipod.str(string ("0"))
waitcnt (clkfreq*2 + cnt) 'pause
Ipod.str(string ("1"))
waitcnt (clkfreq*2 + cnt) 'pause
Ipod.str(string ("250"))
waitcnt (clkfreq*2 + cnt) 'pause
won't work for your situation. You want to send the single byte whose value is 255. Use
Ipod.tx(255)
instead. Do the same thing for all of the bytes. The .str call sends a string of characters, so the above will send "2", then "5", then "5", not the value 255.
waitcnt(clkfreq*2 + cnt)
also won't work for you. It causes a 2 second pause, not a 2 ms pause. Do this instead
waitcnt(clkfreq/500 + cnt)
The reason is that clkfreq is the number of system clocks in one second (read the Propeller Manual for specifics).
Don't be surprised if this doesn't work any better than the BS2_Functions version. They do essentially the same thing. It's possible, but I doubt that the iPod is so timing sensitive that a difference of a fraction of a millisecond will change anything.
Gratzie!
Propeller P0 (internal pin#1 ) ===> Ipod Pin 13 (TX)
Propeller P1 (internal pin#2 ) ===> Ipod Pin 12 (RX)
Ipod pin 21 ===> 500K resistor =====> to GND (3.3V)
Ipod pin 11====>to GND (3.3V)
To this method you will pass a pointer to to the bytes you want to send; these will be stored in a dat statement like this:
The reason you have to pass the count (of bytes to send) is that this allows you to send zeroes (the normal .str() methods use zero as the end-of-string indicator). The final parameter is the pacing between bytes. To simulate your BS2 command you would do this:
The @ symbol provides the address of (a pointer to) the bytes stored in the dat statement called cfg1. There are seven bytes and you want two milliseconds in between each.
Now... you've piqued my interest in hooking up my iPods. Where can I find the connections and protocol?
So instead of BS2#Inv or %1100 what do I use? thats the signal inverter?
I used fro the Bs2 the Sparkfun Logic Level Converter
http://www.sparkfun.com/products/8745
Note: I used RX2 and TX2 as the pin connections for the iPod in the code attached above.
http://nuxx.net/wiki/Apple_Accessory_Protocol
But you have to convert those HEX to DEC. Let me know if you have problems.
No you don't, you just have to use "$" instead of "0x" to indicate hex for the BASIC Stamp or the Propeller. I would suggest using hex notation to reduce code errors when lifting sequences from that page (or others like it).
What I was looking for is a link to the physical connections on the connector to the iPod and, hopefully, a source of experimental connectors.
Picture of my setup attached if you like to take a look.
Edit: in your earlier post you say that P0 goes to iPod pin 12, but in that photo it looks like P0 is going to iPod pin 13 and P1 is going to iPod pin 12.