# Transmitting ASCII 'A' over SPI Protocol

I'm working on a project that involves connecting directly from the TRS jack of an iPhone to a SPI port on a microcontroller.

So the iPhone is the master and the microcontroller is the slave

So let's say the left speaker channel of the iPhone is responsible for generating clock signals

Now how do I transmit for example a single ASCII byte 'A' from the master to the slave?

I can see that each time the clock edge rises ( let's say passes zero ), both master and slave read off a new bit -- whatever the state of the respective MISO/MOSI

But how to byte-align?

Binary for 'A' is 0100 0001

How do we distinguish that leading 0 from the silence that preceded?

It seems to me that a sensible protocol would be to use 0xFF or something as a start Sentinel, and have the next byte dictate the number of bytes ( between 1 and 256 ) in the packet that is to come.

And then these bytes get sent one after the other, may be followed by a parity byte.

Maybe each byte would have parity bit...?

As soon as this ' packet ' has arrived, the decoder could start looking for another start Sentinel.

So that's how I would go about designing SPI. so I'm trying to find some documentation that tells me how it is actually done.

But I'm getting really frustrated bouncing around Google / Wikipedia / IRC

Is there someone out there who understands this protocol, and wouldn't mind giving me a really simple example usage -- sending the single character 'A' via SPI

• I'm not sure how easy this will be to do. The audio output from an iPhone (and basically every other headphone-jack) is both AC-coupled, and has filters that block frequencies above 20Khz and below 20Hz. Apr 26 '12 at 5:27
• You may have to look into 8b/10b encoding, to achieve a proper DC balance, due to the AC-coupled nature of the headphone interface. Also, your voltage levels will likely need some thresholding and level-translation. You will not be able to just plug wire the MCU directly onto the headphone connector. Apr 26 '12 at 5:29
• Lastly, I would think this would be much easier to do with bit-banged SPI, rather then trying to finangle a MCU's onboard SPI module into handling the unusual start and stop conditions. By doing the deciding in software, you could have much finer control over the behaviour of the decoder, and handle start and stop conditions more cleanly. Apr 26 '12 at 5:31
• Incidentally, 0xAA and 0x55 are more commonly used for frame synchronization then ascii "A". 0xAA is 10101010 in binary, and 0x55 is 01010101. The repeating patterns make them easy to recognize. Apr 26 '12 at 5:33