We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi All,
I am trying to produce sound on the speaker attached on the mcb1700 board. Keil installation comes with some examples one of which is the use of usb audio driver which basically plays any sound from your pc onto the mcb1700 speaker. Is it possible to use windows api with keil so that I can use windows.h file which lets me call playsound() function available in the api for producing sound on windows ? Will this then be played on the mcb1700 speaker ?
Thank you all for your time.
Either take a wav file and convert to bin/hex data and include in your source code.
Or make some code that creates a sine wave on-the-fly.
Or make a USB project where you say you are a USB sound card and take sound from windows and send to loudspeaker.
PWM or DAC needed for driving that speaker.
I already have the code that reflects sound produced (like a song played on windows media player) to the speaker on mcb1700 board. But is there a way I can make use of the inbuilt sounds available in windows from keil ie. can I invoke the play sound function available in windows api from keil ? I know I can do this in C or C# when I include the windows.h file in Dev C.
The windows API, functions and libraries are not available on the embedded platform.
So, I guess I cannot use the usbaudio approach of using mcb1700 speakers to play the sound produced on windows. I know there is another way of producing sound using DAC on the board. I looked the example but it uses DMA. Can anybody please explain me why the example uses DMA to generate the sound ? Also, how does DAC work exactly? I know that the output of DAC is connected to the speaker.
/**************************************************************************** * $Id:: dactest.c 6092 2011-01-06 22:55:04Z nxp12832 $ * Project: NXP LPC17xx DAC example * * Description: * This file contains DAC test modules, main entry, to test DAC APIs. * **************************************************************************** * Software that is described herein is for illustrative purposes only * which provides customers with programming information regarding the * products. This software is supplied "AS IS" without any warranties. * NXP Semiconductors assumes no responsibility or liability for the * use of the software, conveys no license or title under any patent, * copyright, or mask work right to the product. NXP Semiconductors * reserves the right to make changes in the software without * notification. NXP Semiconductors also make no representation or * warranty that such application will be suitable for the specified * use without further testing or modification. ****************************************************************************/ #include "lpc17xx.h" #include "type.h" #include "dac.h" #include "dma.h" extern volatile uint32_t DACDMA0Done, DACDMA1Done; /***************************************************************************** ** Main Function main() ******************************************************************************/ int main (void) { uint32_t i = 0; volatile uint32_t regVal; #if DAC_DMA_ENABLED uint32_t *src_addr; #else uint32_t m; #endif /* SystemClockUpdate() updates the SystemFrequency variable */ SystemClockUpdate(); /* Initialize DAC */ DACInit(); #if DAC_DMA_ENABLED src_addr = (uint32_t *)DMA_SRC; /* Fill the pattern in the DMA source memory */ for ( i = 0; i < DATA_LENGTH; i++ ) { *src_addr = (uint32_t)((i<<6)|(DAC_BIAS)); /* pre format the data to DACR register */ src_addr++; } DMA_Init(); /* on DMA channel 0, source is memory, Destination is DAC */ /* Enable channel and IE bit */ DMAChannel_Init( 0, M2P ); LPC_DAC->CTRL |= (0x1<<3); /* DMA enabled on DAC */ LPC_GPDMACH0->CConfig = 0xC001|(0x00<<1)|(DMA_DAC<<6)|(0x01<<11); while ( 1 ) { /* Wait for DMA0 to finish. */ while ( !DACDMA0Done ); DACDMA0Done = 0; DMAChannel_Init( 0, M2P ); /* Set TC int mask, channel enabled, src peripheral is memory(0x0), dst peripheral is DAC(9), and transfer type is the M2P(1) */ LPC_GPDMACH0->CConfig = 0xC001|(0x00<<1)|(DMA_DAC<<6)|(0x01<<11); /* During the DMA transfer, a saw wave should be seen on the scope. */ } #else while ( 1 ) { LPC_DAC->CR = (i << 6) | DAC_BIAS; i++; for(m = 1000; m > 1; m--); if ( i == DATA_LENGTH ) { i = 0; } } #endif } /***************************************************************************** ** End Of File *****************************************************************************/
Thanks.
Can we use I2S to interface the speaker that comes on the development board?
Yes, you can use I2S - if you have an external chip that listens to I2S and outputs sound to a speaker. I2S itself isn't for connecting to a speaker. It is a digital interface for streaming digital sound data to sound chips.