cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32F4Discovery]Unable to do basic audio

m239955
Associate
Posted on June 01, 2013 at 13:10

Hi all.

I got my first f4-discovery some day ago from my robotics and embedded systems professor. I wanted to try some basic audio manipulation, but it turned out i can even output some synthetic wave from the codec. I based my code on the stm32f4_discovery_audio_codec.[ch] library, but maybe i fail in configure correctly the whole. Here is the code i wrote.

#include <stm32f4_discovery.h>
#include <stm32f4xx_conf.h>
#include <stm32f4_discovery_audio_codec.h>
void
initWave(
void
);
uint16_t buffer[256];
uint16_t index;
int
main (
void
)
{
int
volume = 100;
int
AudioFreq = 256*440;
STM_EVAL_LEDInit(LED3|LED4);
STM_EVAL_LEDOff(LED3|LED4);
initWave();
/* Initialize I2S interface */
EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S);
/* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */
EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, volume, AudioFreq); 
index = 0;
EVAL_AUDIO_Play((uint16_t*)buffer, 256);
while
(1);
return
0;
}
void
initWave(
void
)
{
uint16_t i;
for
(i = 0; i <= 0xFF; i++)
{
buffer[i] = ((i & 0x80) >> 7) * 0xFF;
}
}
void
EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size)
{
index = 0;
STM_EVAL_LEDToggle(LED4);
EVAL_AUDIO_Play((uint16_t*)buffer, 256);
}
uint16_t EVAL_AUDIO_GetSampleCallBack(
void
)
{
STM_EVAL_LEDToggle(LED3);
return
buffer[index++];
}

And this is the head of stm32f4_discovery_audio_codec.h where i set the defines:

/*------------------------------------
CONFIGURATION: Audio Codec Driver Configuration parameters
----------------------------------------*/
/* Audio Transfer mode (I2S Interrupt) */
#define I2S_INTERRUPT /* Uncomment this line to enable audio transfert with I2S interrupt*/ 
/* Audio Transfer mode (DMA, Interrupt or Polling) */
#define AUDIO_MAL_MODE_NORMAL // Uncomment this line to enable the audio 
//Transfer using DMA
//#define AUDIO_MAL_MODE_CIRCULAR // Uncomment this line to enable the audio 
//Transfer using DMA
/* For the DMA modes select the interrupt that will be used */
#define AUDIO_MAL_DMA_IT_TC_EN //Uncomment this line to enable DMA Transfer Complete interrupt
//#define AUDIO_MAL_DMA_IT_HT_EN //Uncomment this line to enable DMA Half Transfer Complete interrupt
//#define AUDIO_MAL_DMA_IT_TE_EN //Uncomment this line to enable DMA Transfer Error interrupt
/* Select the interrupt preemption priority and subpriority for the DMA interrupt */
#define EVAL_AUDIO_IRQ_PREPRIO 0 /* Select the preemption priority level(0 is the highest) */
#define EVAL_AUDIO_IRQ_SUBRIO 0 /* Select the sub-priority level (0 is the highest) */
/* Uncomment the following line to use the default Codec_TIMEOUT_UserCallback() 
function implemented in stm32f4_discovery_audio_codec.c file.
Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition 
occurs during communication (waiting on an event that doesn't occur, bus 
errors, busy devices ...). */
#define USE_DEFAULT_TIMEOUT_CALLBACK
/* Enable this define to use the I2S DMA for writing into DAC register */
//#define DAC_USE_I2S_DMA
/*----------------------------------------------------------------------------*/

Basically i have 256 samples from a square wave and i want the codec to generate a signal with 440Hz, so i want the codec to output the 256 samples 440 times per second, is it right? Have you some advice for me? It is becoming really frustrating. Thank you for your help #stm32f4discovery-audio-codec
1 REPLY 1
m239955
Associate
Posted on June 02, 2013 at 12:10

no one has a suggestion?