cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 F3 problem in playing audio

b2
Associate II
Posted on August 05, 2014 at 07:00

Hi,

I am new to STM32 and probably asking a dumb question. I have designed a board to play audio files off a SPI flash. I can read and write to flash properly, but when I try to send the audio data to the speaker all I hear is the hissing noise.

 

My wav file is 8Khz PCM mono. I converted the wav file to C using HxD. I tried playing the audio from my computer and connected the audio out to my amp on the board and I can hear the sound.

I am not parsing the audio samples as I thought I can just send the data to my dac and dac will pump the buffer to the amp so I can hear the sound. Now I would like to ask you experts, is the endianness of the audio file important? Do I have to parse the file and check for the little endian or big endian?

Any help would be appreciated.

Thanks

#stm32-audio-dma
7 REPLIES 7
Posted on August 05, 2014 at 14:15

Do you have the output paced appropriately?

Can you review the DAC output with a scope? Try generating DC, and sine-wave type output, and review that.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
b2
Associate II
Posted on August 05, 2014 at 22:38

Hi Clive,

I am using this code to test the output of GPIOA pin 4, i.e DAC channel 1

static void TIM_Config(void)

{

  /* TIM7 Periph clock enable */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);

  /* Time base configuration */

  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

  TIM_TimeBaseStructure.TIM_Period = 8999;    //SYSTEM_CORE_CLOCK/SAMPLE_RATE - 1

  TIM_TimeBaseStructure.TIM_Prescaler = 0;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM7, &TIM_TimeBaseStructure);

  /* TIM7 TRGO selection */

  TIM_SelectOutputTrigger(TIM7, TIM_TRGOSource_Update);

  TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);

  /* TIM7 enable counter */

  TIM_Cmd(TIM7, ENABLE);

  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable the TIM2 gloabal Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

}

static void DAC_Config(void)

{

  /* DAC Periph clock enable */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

  /* GPIOA clock enable */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  /* Configure PA.04 (DAC_OUT1) as analog */

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

}

void TIM7_IRQHandler(void)

{

        //Toggle GPIOA Pin 4 on and off when interrupt trigger

       GPIO_ResetBits(GPIOA, GPIO_Pin_4);

       if(TIM_GetITStatus(TIM7,TIM_IT_Update) != RESET)

       {

              TIM_ClearITPendingBit(TIM7, TIM_IT_Update);

              GPIO_SetBits(GPIOA, GPIO_Pin_4);

       }

}

Posted on August 06, 2014 at 00:20

Well that's totally not going to work, you are driving the pin to a digital level, not as an analogue one using the DAC.

Review:

STM32F3-Discovery_FW_V1.1.0\Project\Peripheral_Examples\DMA_RAM_DAC\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
b2
Associate II
Posted on August 06, 2014 at 22:01

Hi Clive,

That example helped me getting DAC sorted. I proceeded with my audio project using the example code. I need to initialize timer for 8khz and my initializing code is below

void timerInit(void)

{

    TIM7ARRValue = SystemCoreClock/8000 - 1; 

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7,ENABLE);

    TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

    TIM_TimeBaseStructure.TIM_Period = TIM7ARRValue - 1;

    TIM_TimeBaseStructure.TIM_Prescaler = 0;

    TIM_TimeBaseStructure.TIM_ClockDivision = 0;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

    TIM_SelectOutputTrigger(TIM7, TIM_TRGOSource_Update);

    TIM_SetAutoreload(TIM7, TIM7ARRValue);

    /* TIM17 enable counter */

    TIM_Cmd(TIM7, ENABLE);

Isn't it correct?

Posted on August 06, 2014 at 22:17

Configure TIM7, not TIM6

Don't reconfigure the Auto Reload with the wrong value.

Not sure which timer triggers are connected to the DAC on the F3 parts, you'd want to check that and the suitable DMA channel configuration.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
b2
Associate II
Posted on August 25, 2014 at 00:58

Hi,

Finally I have configured and got the audio playing. But now I am stuck with another problem of audio not playing completely. When I am playing 10 seconds of audio I can only hear the first 8 seconds. I tried reading the index of the audio sample array and it is reaching to the end. any ideas?

Thanks

Posted on August 25, 2014 at 04:48

any ideas?

Not really much to work with there.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..