Audio Sine Tone Tutorial: Step 5

Step 5: Add code to initialize the application and generate the audio sine tone

In the source file audio_sine_tone.c, locate the function main (near line 512). This function initializes the application and generates the audio sine tone.

image46.png

The numbers below describe each section of main as shown in the figure above.

1

Initialization of SAM V71 system.

  • Initialize the system clock by calling sysclk_init. This involves setting up of flash wait states and programming of the system/peripheral clock(s).
  • Initialize the SAM V71 Xplained Ultra Evaluation Kit by calling board_init. This involves setting up the watchdog, memories, and I/O port.

2

Initialization of UART interface used as a debug console.
The UART is initialized by calling configure_console. The debug message is printed on the console. The debug message prints the name of the application ("— Audio sine tone using SSC on WM8904 —"), board name (SAMV71-XLTRA) and the date and time of compilation.

3

Initialization of serial interface to the WM8904 module.
The serial interface to the CODEC WM8904 is through TWI (for commands) and SSC (for data) peripherals. The WM8904 serial interface initialization maps the multiplexed I/O pins to be used by peripheral. It also sets up and enables the clock to TWI peripheral by calling wm8904_twi_init.

4

Configuration of CODEC WM8904 module, SSC and XDMAC peripherals.

  • CODEC WM8904 is configured by calling function configure_codec. Based on the source of the reference clock (PCK2), CODEC WM8904 is configured in master or slave mode as discussed in the section on implementation of Audio CODEC Configuration.
  • SSC peripheral is configured to interact with an I2S interfaced Codec WM8904 module by calling function configure_ssc. Based on the source of the reference clock (PCK2), SSC is configured to act as master or slave of the audio data transfer as discussed in the section on implementation of SSC configuration.
  • XDMAC peripheral is configured to facilitate SSC peripheral’s interaction with I2S interfaced CODEC WM8904 module by calling function configure_xdma. XDMAC is configured to implement a circular linked list of two transfer descriptors acting as ping-pong buffers of audio data transfer as discussed in the section on implementation of XDMAC configuration.

5

Enable the CODEC master Clock.
The CODEC WM8904 is provided a reference clock (acting as MCLK) based on the oversampling rates supported by the CODEC.
Before setting up the prescaler for the reference clock, PCK2 clock source is disabled by calling pmc_disable_pck.
Setup the prescaler for the reference clock source by calling pmc_pck_set_prescaler. Based on the value of configuration macro PCK2, either a slow clock of 32768 Hz or a 12 MHz clock from the main source is selected by calling pmc_pck_set_source. The master clock to the CODEC is enabled by calling pmc_enable_pck.

6

Start Audio Playback.
Enable the SSC transmission by calling ssc_enable_tx, and enable the XDMAC to start the data transfer by calling xdmac_channel_enable.

Once started, the playback continues as the audio sine data is stored in the form of a lookup table in the array AudioBuffer. When XDMAC is enabled, it starts placing the contents of AudioBuffer onto the SSC transmit register. The XDMAC trigger for the next data transmission is the completion status of the last transaction. When the AudioBuffer transmission is completed, the XMDAC switches to the next descriptor in the linked list. The source address of the audio data in the linked list descriptor is same (AudioBuffer) as earlier. Transmission completes, as with earlier linked list descriptors and XDMAC moves back to the first descriptor in the list. The XDMAC switches between the two descriptors while transmitting the sine tone data through SSC to the CODEC. The CODEC WM8904 plays back the received data.



Next Step >

© 2018 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.