By Zhi-Hern Loh
This program was designed for a ATMELMega128 MCU connected as specified on the hardware design page.
The program design was organized in the following main groups
The following paragraphs document the design of the MP3 player program. There are explanations and instructions for the usage of the functions included in the main program groups outlined above.
Code used in debugging and development are also documented here.
The serial I/O handler was interrupt based. Strings to be written to the serial interface were stored in a string located in sram. To write to the serial port, the program needed to check a output ready flag(OUT_RDY) and then call a function to write a string to the output buffer. Conversely, input from the serial interface was written to another string a character at a time until a carriage return was detected. Upon the detection of a carriage return, a input ready flag (IN_RDY) would be set. When the IN_RDY flag is set, the program can read the buffer by calling a specific function.
Writing to the serial interface requires the use of the following functions
Using the STA013 requires that the decoder be initialized with a series of about 2000 bytes containing register addresses and data. These 2000 bytes are stored in a .bin file. I used a Intel hex (click here for Intel hex format) version that was also used in the previous MP3 project by another group. CodeVision C's chip programmer can load this Intel hex file and write to the eeprom of the MCU.
Calling STA013_Init() initializes the STA013 by executing the following:
After the STA013 decoder has been initialized, the following functions can be used:
Other functions good for debugging include
Using the Xmodem protocol is straight forward when we are not playing back a MP3 concurrently. However in this project, the available memory on the Mega128 is insufficient to buffer the entire MP3 song before starting playback. In order to play the song smoothly, I employed a circular buffer to store the MP3 data before sending them to the STA013 decoder.
The Xmodem receiver must then handle both download and playback concurrently to prevent buffer over or under-flows. Thus I could not afford function calls within the receiving function because of this time critical nature. The function calls would have taken too many cycles to get in and out. This resulted in a very long function that polls the UART as well as sends MP3 data bytes to the decoder. The length of the function makes it difficult to read and understand. However the underlying principle of the receiver is similar to the flowchart of the Xmodem protocol.
The external functions in Xmodem.c are
The MP3 data was written into a cyclic buffer. The algorithm is as follows:
The user interface consists of 4 buttons.
User prompts and system status are shown on both the LCD and the serial interface. While Xmodem transfer is in progress, the serial interface cannot prompt the user or display information and hence the LCD is used.
I wrote a C program for the PC to do convert a .mp3 file to a header file that CodeVision C could read. This header file contained the MP3 data as bytes in a unsigned char array stored in flash. Click to see the code and example header file.
There are also some STA013 function calls that were useful during development.