cancel
Showing results for 
Search instead for 
Did you mean: 

Audio How to play audio files using STM32F103C8T6

itrajusankar
Associate

Hi,
I want to design a voice announcement system using the STM32F103C8T6.
My requirement is to Load WAV audio files from an SD card and play them using the STM32, without using any external DAC.

I would like guidance on how to start the project using STM32CubeMX / STM32CubeIDE, including:

  • Peripheral configuration in CubeMX

  • Audio playback method without a DAC (for example, PWM-based audio)

  • Basic coding structure to read WAV files from an SD card and play them

Any help or reference projects would be greatly appreciated.

 

I have design hardware also here attachment is there please go through it ...Thank you 

 

 

15 REPLIES 15

@itrajusankar The examples given by @MOBEJ refer to an external audio DAC, which would also be possible with an STM32F103. However, apart from the schematics, you have not provided many details so far, neither that it is an genuine STM32F103 and not one of the many counterfeits, nor the expected maximum audio frequency, nor an explanation of what you mean by ‘not as good as expected’ in the result.

We can only speculate at this point and assume that you are using TIM4 as a PWM output on PB6 and PB8, correct?
I must also assume that you are generating an internal frequency of 72MHz from the HSE=8MHz. Your low-pass filter of 1k+100nF, which you have on each of the two PWM outputs, has a cut-off frequency of 1591Hz, which could be suitable for subwoofers at best. For reasonably good audio quality (which also needs to be defined first), I assume a minimum PWM resolution of 14 bits. With these parameters, we can already estimate the result: 72MHz/16384 ~ 4394Hz, which is extremely attenuated by the low-pass filter – this cannot produce a meaningful result.

Regards
/Peter

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi,

why not F303 ? has DAC ... and about same price + pinout.

If you feel a post has answered your question, please click "Accept as Solution".

> For reasonably good audio quality (which also needs to be defined first), ...

About 5kHz audio frequency (which means twice the sampling frequency) is usually considered sufficient for good speech comprehension. I would choose the standard sampling rate of 11250Hz.

 

Indeed, 4kH is (was?) considered "toll quality" for telephone lines...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

And the average for AM-based radio. Good old times ...

Ozone
Principal III

But back to the topic ...

The STM32F100C8 does have a DAC.
Many other STM32 variants as well.
And there are relatively cheap external DACs with a serial interface (e.g. SPI).

I think using e.g. PWM instead of a DAC is saving on the wrong things.
One needs to take the subsequent audio PA stages into consideration as well, and PWM would create a lot of undesired harmonics that need to be filtered out.