Page 1
Note: Throughout this document, and unless otherwise specified, the term of I S will be used to refer to the I S feature of the SPI peripheral that is implemented in high-density STM32F103xx microcontrollers. May 2008 Rev 1 1/26 www.st.com...
AN2739 S general description S general description S protocol S (IC-to-IC sound) is an audio data transfer standard using a three-line bus for serial and synchronous data transmission. Data are transmitted on the SD line (Serial Data) in Little Endian format (MSB first). Data length is not limited (usually 16/20/24/32/64 bits).
S general description AN2739 Figure 2. S protocol signal description and configuration Transmitter Receiver Transmitter Receiver Transmitter = Master Receiver = Master Controller Transmitter Receiver Controller = Master ai15113 STM32F103xx I S feature presentation The STM32F103xx implements the I S feature as a mode included in the SPI peripheral. The user has to choose either the SPI mode or the I S mode (software configuration).
Page 7
AN2739 S general description To decide if MCLK should be generated or not, the following facts have to be taken into consideration: ● The external I S device requirements (codec/DAC). In general these devices need a master clock (usually at the rate 256 × F ) to perform internal and sampling operations.
Implementation example AN2739 Implementation example General overview The example presented in this application note aims at providing typical hardware and software implementation basics for an audio application like portable audio players, sound synthesis systems, speech recorders, cell phones or interactive control boards. Typically, the system embeds: –...
AN2739 Implementation example Other board resources are used to interface the application: ● Audio codec: AK4343 implemented on the STM3210E-EVAL and connected to the I2S2 interface (and to relative passive components). ● Stereo audio speaker and audio jack connected to the audio codec and implemented on the STM3210E-EVAL.
Implementation example AN2739 When the MCLK clock is enabled (by configuring the relative configuration register), MCKI jumper (JP18) should be configured in the 2<>3 position in order to drive the MCLK signal from the STM32F103xx I S interface to the codec MCLKI pin. The default codec configuration used in this application note is: ●...
AN2739 Implementation example For more details, refer to the STM3210E-EVAL evaluation board user manual on www.st.com. Firmware description This application note is based on: ● the STM32F10xxx firmware library ● the I2S_CODEC driver firmware (offering the main functions required to control the...
Implementation example AN2739 Table 2. I2S_CODEC driver high-level functions (continued) Function name Description Increments the audio file pointer by a fixed step (percentage of the I2S_CODEC_ForwardPlay file length) then continues playing. Decrements the audio file pointer by a fixed step (percentage of I2S_CODEC_RewindPlay the file length) then continues playing.
AN2739 Implementation example Table 4 lists all the parameters that have to be set in order to correctly configure the application (some are automatically set by the I2S_CODEC_Init function, others are constants defined in the driver files). Table 4. Configuration parameters list Parameters Values Location...
Implementation example AN2739 ● I2S_CODEC_Play function This function starts playing the audio file from a programmable position. Table 6. I2S_CODEC_Play function Function name I2S_CODEC_Play Prototype u32 I2S_CODEC_Play(u32 AudioStartPosition) Sets the memory read address to AudioStartPosition and enables the I Behavior description interrupt to begin sending audio data to the codec.
AN2739 Implementation example Medium-level functions Medium-level functions are used to better control some basic functionality and the audio stream. Table 8 presents these functions. Table 8. I2S_CODEC medium-level driver functions Function name Description Sends the audio data using the SPI2 peripheral and checks the audio play status (if a (Pause/Stop) command is pending) by calling the I2S_CODEC_UpdateStatus function.
Implementation example AN2739 Low-level functions Some low-level functions provide flexible management of the memory (SPI Flash/NOR, etc.). Other types of memories can be supported simply by replacing the body of these low- level functions by the corresponding functions for the memory. Example: the Media_Init function should contain the entire memory initialization procedure.
Page 17
AN2739 Implementation example Figure 6. Driver’s functional flowchart 2 I2S_CODEC_Data End of stream Transfer Codec configuration AudioReplay ==0 phase Audio file Send dummy Read data from AudioReplayCount data on I2S2 memory > 0 Send data on I2S2 AudioReplayCount-- Stop Increment AudioReplayCount = data index Play...
Implementation example AN2739 2.3.2 Demo firmware description The demo uses the i2s_codec driver functions to control the audio stream. Other functions are implemented to make the application interactive. Two main functions are handled by the application: ● Joystick and push-button input control ●...
AN2739 Implementation example LCD_Update function The LCD configuration and the current audio stream information display operations are performed by the LCD_Update function as detailed in Table Table 12. LCD_Update function Function name LCD_Update Prototype void LCDUpdate(u32 Status) Updates the information displayed on the LCD according to the parameter Behavior description Status.
Page 20
Implementation example AN2739 Demo firmware flowcharts Figure 7 presents the overall function flowchart. Figure 7. Demo’s functional flowchart 1 SystemTick event Main.c Up/down push-putton pressed Configure SystemTick Key push-button pressed LCD configuration and welcome screen display Right/Left push-button pressed Joystick and Key configuration SEL push-button pressed...
Page 21
AN2739 Implementation example Figure 8. Demo’s functional flowchart 2 Up/Down Key push-button Right/Left push-button SEL push-button push-button pressed pressed pressed pressed Current status = Current status = LCD_Update Forward/rewind Playing Playing (STOP) LCD_Update LCD_Update LCD_Update LCD_Update LCD_Update Stop (ALL) (VOL) (PAUSE) (PLAY) (FRWRWD)
Implementation example AN2739 ● Use the STMicroelectronics DFU demonstration firmware to compile any audio file and load it into the memory (for more details, refer to the DFU section in the STM3210E- EVAL evaluation board demonstration user manual). Once this DFU image is loaded, the file address has to be set (using the AUDIO_FILE_ADDRESS constant in the main.h file) and the application note firmware can then run correctly.
Conclusion AN2739 Conclusion This application note explains the basics to build an interactive audio playing application using the STMicroelectronics evaluation board with an audio codec, a speaker, a headphone jack and an optional LCD. The application may be enhanced by adding/removing some options depending on the requirements.
AN2739 Revision history Revision history Table 13. Document revision history Date Revision Changes 30-May-2008 Initial release. 25/26...
Page 26
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.
Need help?
Do you have a question about the STM32F103 Series and is the answer not in the manual?
Questions and answers