info:controlling_ipod_with_atmel32
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
info:controlling_ipod_with_atmel32 [2008/11/26 18:38] – tomgee | info:controlling_ipod_with_atmel32 [2008/11/26 19:15] (current) – tomgee | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | Controlling an iPod with an Atmega32 | + | ===== Controlling an iPod with an Atmega32 |
- | Introduction | + | |
+ | **Introduction**\\ | ||
Have you ever imagined, "What does that cable I plug into my iPod every day actually do, and how do I take advantage of it for myself?" | Have you ever imagined, "What does that cable I plug into my iPod every day actually do, and how do I take advantage of it for myself?" | ||
Line 85: | Line 86: | ||
The button_release state should occur when the user has finished sending a mode 0x02 command. The t_buffer is set to the button release command, which is of mode 0x02, and is transmitted to the iPod. The state then proceeds to Send. | The button_release state should occur when the user has finished sending a mode 0x02 command. The t_buffer is set to the button release command, which is of mode 0x02, and is transmitted to the iPod. The state then proceeds to Send. | ||
- | {{info: | + | {{info: |
+ | |||
+ | Helper functions we used: | ||
+ | |||
+ | initialize() sets up the LCD display and determines the baud rate that we use. Since the iPod transmits at 19200 bits per second, we set UBRRL to 51. Additionally, | ||
+ | |||
+ | buttons() is called every millisecond, | ||
+ | |||
+ | As it turns out, when an iPod receives a mode 0x02 command, it continues performing that operation until a button release command is sent. However, the iPod does not send any acknowledgment regarding mode 2 commands, unlike mode 4 commands. Thus, we decided to err on caution and simplicity, and send the command multiple times if the button is held down noticeably. It would be an interesting question to ask if the iPod functions similarly for internal button presses (e.g. on the click wheel). Clearly, volume up/down is handled differently on the iPod due to the wheel motion. | ||
+ | |||
+ | Finally, we have a helper function called lcd_scroll(). This helper function is called every 300 ms, and is used to scroll the title, artist, and album fields on our little 16x2 LCD screen. These fields need to be scrolled if the fields are longer than 16 bits, which would not display nicely on our LCD screen. It works by copying over the relevant part of r_buffer, namely the part that includes the string fields, to another array, lcdbuffer. That array is then copied over into a " | ||
+ | |||
+ | puts_int() starts transmitting t_buffer through the UART. It resets all through t_index and t_ready, then calls put_char() to transmit the first character of t_buffer. Afterwards, the interrupt transmits each character at a time. | ||
+ | Tricky Stuff | ||
+ | |||
+ | To send and receive, we initially used Bruce Land's serial transmission code and modified the stop conditions to checksums instead of null terminators. Additionally, | ||
+ | |||
+ | Within the receive interrupt, we realized that a parameter within an iPod response could erroneously match the checksum. For example, when sending back the album title "Good News for People Who Like Bad News," one of our implementations stopped at the space character (' ') because its ASCII code, 0x20, matches the incomplete computed checksum. The old implementation detected this match and considered it to be the end of the transmission, | ||
+ | |||
+ | How the Send and Receive states intertwined was easily the trickiest part of the code. The sources we used did not explicitly tell us every response an iPod would give us -- for example, mode switching was not well documented and we were not aware of its necessity. Originally, we were planning to ignore responses that we did not care about. After spending some time in lab, we decided that this was not the correct approach, and spent time determining all the responses. | ||
+ | |||
+ | When the iPod leaves mode 4 and enters mode 2, the iPod can ignore commands! When the user presses the physical play button on the iPod, there are no issues. In contrast, the iPod ignores the serial Play command up to three times! We believe there is a command in the sequence missing that we are not aware of and/or is not documented. We cannot see what a " | ||
+ | |||
+ | Finally, John Sicilia showed us a clever way of checking the receive buffer using the LEDs. Light up the LEDs according to the character in the buffer, delay for several seconds, turn the LEDs off for some time, and then move on to the next character in the buffer. Prior to this method, we had been looking at the waveform on the oscilloscope, | ||
+ | |||
+ | |||
+ | |||
+ | for(k=0; k<11; k++) | ||
+ | { | ||
+ | PORTB = t_buffer[k]; | ||
+ | delay_ms(5000); | ||
+ | PORTB = 0xFF; | ||
+ | delay_ms(500); | ||
+ | } | ||
+ | while(1); | ||
+ | |||
+ | **Hardware Design**\\ | ||
+ | |||
+ | The microcontroller outputs a high and low voltage of 5V and 0V respectively. However, the iPod operates at a maximum of 3.3V for high. Thus, for the serial transmission line, we created a voltage divider, so that when the line is pulled to 5V, the iPod sees 3.3V. The high level schematic is below. | ||
+ | |||
+ | {{info: | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | {{info: | ||
+ | |||
+ | Code for this project is in the file ipod_avr32.c | ||
+ | |||
+ | **Conclusions**\\ | ||
+ | |||
+ | The results of this project met our expectations. We wanted to both control and receive from an iPod with a microcontroller, | ||
+ | |||
+ | {{info: | ||
+ | |||
+ | **Future Design Aspirations**\\ | ||
+ | |||
+ | If we had more time available, we would have liked to implement an IR receiver with the microcontroller. Thus, a user could use an IR remote to send commands to the microcontroller, | ||
+ | Ethics | ||
+ | |||
+ | We believe that our project was consistent with the IEEE Code of Ethics. For example, we believe that our project is safe to individuals and the public at large, and we would promptly notify everyone if this ever changed. We believe that we have been honest about our project' | ||
+ | |||
+ | In the interest of full disclosure, one of us was formerly employed by Apple (then known as Apple Computer). It should be noted that none of the material referenced in this project or on this page resulted either directly or indirectly from any material obtained during employment or with any use of Apple-owned resources, such as hardware or documentation. We have made careful efforts to ensure that nothing done here would compromise any previous or (hopeful) future employment agreements and that we have respected intellectual property throughout. | ||
+ | |||
+ | No animals were harmed in the making of this project. Cornell students were merely deprived of sleep. |
info/controlling_ipod_with_atmel32.1227742684.txt.gz · Last modified: 2008/11/26 18:38 by tomgee