Shop OBEX P1 Docs P2 Docs Learn Events
Propeller to Ipod Communication — Parallax Forums

Propeller to Ipod Communication

Luis_PLuis_P Posts: 246
edited 2011-06-13 21:55 in Propeller 1
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
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-05 08:00
    The problem probably has to do with your choice of system clock. You've specified an 8MHz (_XINFREQ) crystal (XTAL1) with a PLL multiplier of 16 (PLL16X). Most Propeller chips will not work at 128MHz (16 x 8). Either use a lower frequency crystal (typically 5MHz) or use a lower PLL multiplier like 8 (PLL8X) for a system clock frequency of 64MHz (8 x 8).
  • Luis_PLuis_P Posts: 246
    edited 2011-06-05 09:38
    I dont' have a 5MHz crystal, I will try with 4MHz I have one in somewhere.
    Mike what is a PLL multiplier like 8 (PLL8X) ? that refers to the crystal as well? or is another component attached to the chip?
  • Luis_PLuis_P Posts: 246
    edited 2011-06-05 11:23
    What a pain! The 4MHz Crystal doesn't work either.
    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.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2011-06-05 12:06
    This should work fine with an 8Mhz Crystal:
    CON
    _clkmode = xtal1 + pll8x ' Feedback and PLL multiplier
    _xinfreq = 8_000_000 ' External oscillator = 8 MHz
    
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-05 12:27
    The PLL (Phase Locked Loop) is internal to the Propeller. It effectively multiplies the input frequency by a specified constant (1x, 2x, 4x, 8x, 16x).
  • Luis_PLuis_P Posts: 246
    edited 2011-06-05 17:37
    I start thinking that the Propeller doesn't work to send this time of commands (Apple protocole) since the Bs2 works fine. The Ipod talks 3.3V and the Propeller too, it has to be something else...
    Any ideas?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-05 19:02
    The Propeller should work just as well as the BS2. There must be something you're not showing. Did you fix the crystal (and adjust the _clkmode and _xinfreq statements to match)? Are your connections to the iPod really what you've described (and effectively the same as for the BS2)? What you posted has no indenting. I assume the actual program is indented properly. Next time use the [ code ] and [ /code ] tags around your code so the indenting will remain.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-05 19:42
    CodeIpod.jpg
    Mike:
    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?
    1024 x 694 - 74K
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-05 19:59
    There's nothing wrong I can see with your program or with your description of how you've connected the Prop to the iPod. Since this setup worked with a Stamp, it should work with the Prop as well. Maybe someone else can spot something wrong, but I don't see it.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-05 20:04
    Mike: With the Bs2 I use a logic level converter because the stamp serial output is at 5V and the Ipod talks 3.3V. But the propeller is 3.3V right?
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-06 03:57
    Is the iPod timing out? Perhaps you should unload the baggage of the BS2 object and use FullDuplexSerial.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-06 08:32
    Jonny I will like to try your suggestion. Thanks.
    How do I use the FullDuplexSerial? Any example I can use?
    Gracias.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-06 15:18
    FullDuplexSerial is the base standard that almost all of us use. Yes, most of us have increased the buffer size but you may not need that and you've already got in on your machine if you installed the Propeller Tool.

    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:
    ipod.start(iRX, iTX, %1100, 9600)
    

    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.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-06 16:45
    My BS2 code is like this:

    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!
  • Luis_PLuis_P Posts: 246
    edited 2011-06-06 23:01
    I'm trying The FullDuplexSerial I got stuck, take a look Jonny, I'm close? can you help me?

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-07 08:06
    Ipod.str(string("255"))

    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.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-07 08:42
    Thanks Mike I will try when I get home. I will be surprise if works but I have to try. If doesn't work I will have to us the Bs2 instead (more expensive) works perfect I don't know why the Ipod doesn't like the propeller. The only connections I changed on is the "level converter" I removed it. No need since the Propeller and Ipod are 3.3V serial comm.

    Gratzie!
  • Luis_PLuis_P Posts: 246
    edited 2011-06-07 08:57
    Here are the detail connections just in case someone can find something wrong:

    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)
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-07 09:10
    Maybe your level converter for the BS2 version was an inverting level converter? If so, you need to change the Prop version so it doesn't invert the signal. In the future, remember that it's these sorts of questions and problems that you get when you don't post everything. In particular, it's hard to figure out what's wrong when you have one version that works and one version that doesn't work and you've only posted complete information on the version that doesn't work.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-07 09:31
    Luis: I've attached a starter program to get you going. With the BS2 you can embed a bunch of bytes into the SEROUT command; as you've seen, you can't do this directly with the Propeller. No worries, we can code that. I've created a method called ipod_str() that allows you to send a series of bytes with pacing in between. It's pretty easy:
    pub ipod_str(pntr, count, pace)
    
    '' Sends "count" bytes at "pntr" with "pace" milliseconds between each
    
      repeat count
        ipod.tx(byte[pntr++])
        pause(pace)
    

    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:
    dat
    
    cfg1            byte    255, 85, 3, 2, 0, 1, 250
    

    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:
    ipod_str(@cfg1, 7, 2)
    

    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?
  • Luis_PLuis_P Posts: 246
    edited 2011-06-07 09:32
    OK. Got your point. Sorry my bad.
    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
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-07 09:33
    I looked at the schematic for that level shifter; it does not invert signals. Still, you may want to change your initialization to:
    ipod.start(RX2, TX2, %0000, 9_600)
    

    Note: I used RX2 and TX2 as the pin connections for the iPod in the code attached above.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-07 09:43
    The connections are in post 62. Now is hard to find a 500K resistor so use two 1M in parallel. This resistor on pin 21 tells the ipod that a remote command will be sent. the apple protocol is here:
    http://nuxx.net/wiki/Apple_Accessory_Protocol
    But you have to convert those HEX to DEC. Let me know if you have problems.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-07 10:01
    Thanks for the link.
    But you have to convert those HEX to DEC

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-07 10:05
    This is carried by SparkFun. The link has the descriptions of the signals.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-07 10:46
    Thanks, Mike. I started poking around SparkFun but hadn't come across that yet.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-07 11:34
    SparFun has a podbreakout. There is a page in somewhere with pictures, hooking up the ipod to an Arduino, let me see if I can find.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-07 13:44
    ipod_Conn.jpg
    Jonny, Hope you ahve better luck than me. I try your code and Mike's as well and the ipod still not responding. So may be there is something in my connections that is missing.Attachment not found.
    Picture of my setup attached if you like to take a look.
    1024 x 680 - 132K
  • SSteveSSteve Posts: 808
    edited 2011-06-07 16:28
    This looks like it would be a great time to have one of these. If Jon's software doesn't work, it's time to start looking at hardware.

    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.
  • Luis_PLuis_P Posts: 246
    edited 2011-06-07 16:43
    Thanks I already fix my mistake.
Sign In or Register to comment.