WAV File to DAC Problem
Hello,
i read the ST instructions and looked in the EVAL Board example. There they used a audio jack via SPI but in want to play the file direct on DAC.
First to check if the SD Card works i write and read a file to it (works). Then I call the "play_sound" Funktion.
My problems to solve:
- Open the file don't work like the text file -> What's the problem
- How can I transfer the value of buffer one and two to the DAC. May be via DMA
Settings of SD Card and DACs

void play_sound(void)
{
uint32_t WaveDataLength=0;
/* Get Data from SD */
res=f_open(&myFile, "open_sound_mono.wav", FA_READ); // Don't work. SD Card is already mounted and TXT File write and read worked properly
res=f_lseek(&myFile, f_size(&myFile));
res=f_read (&myFile, buffer1, _MAX_SS, &BytesRead);
res=f_read (&myFile, buffer2, _MAX_SS, &BytesRead);
res=f_close(&myFile);
/* Start playing wave */
// Play buffer1 on DAC0 HOWTO ???
buffer_switch = 1;
while((WaveDataLength != 0) )
{
/* wait for DMA transfert complete */
if(buffer_switch == 0)
{
/* Play data from buffer1 */
// Play buffer1 on DAC0 HOWTO ???
/* Store data in buffer2 */
f_read (&myFile , buffer2, _MAX_SS, &BytesRead);
buffer_switch = 1;
}
else
{
/* Play data from buffer2 */
// Play buffer2 on DAC0 HOWTO ???
/* Store data in buffer1 */
f_read (&myFile, buffer1, _MAX_SS, &BytesRead);
buffer_switch = 0;
}
}
// Wiedergabe Stoppen
// WavePlayerStop ???
WaveDataLength = 0;
}
void DAC_setup()
{
HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
HAL_DAC_Start(&hdac, DAC_CHANNEL_2);
//HAL_DAC_Start_DMA(&hdac, DAC1_CHANNEL_1 , pData, Length, Alignment)
HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t*)AUDIO_SAMPLE, 32, DAC_ALIGN_12B_R); //Test with AUDIO_SAMPLE from EVAL Board sample code
}
