In my last post, I have introduced you to the powerful STM32H743VIT6 microcontroller.
Now it is time to test some audio output.
I don’t have any special implementation for the output of analog audio for the STM32H7, but I decided to try to use my generic implementation that is part of by my AudioTools library which is based on the Arduino analogWrite() in combination with a timer.
I adapted the standard example to use stereo and defined the analog pins PA4 and PA5 which are connected to the internal DAC:
#include "AudioTools.h"
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000);
GeneratedSoundStream<int16_t> sound(sineWave);
AnalogAudioStream out;
StreamCopy copier(out, sound);
int pins[] = {PA4, PA5}
// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
// start the analog output
auto config = out.defaultConfig(TX_MODE);
config.setPins(pins);
config.copyFrom(info);
out.begin(config);
// Setup sine wave
sineWave.begin(info, N_B4);
Serial.println("started...");
}
// Arduino loop - copy sound to out
void loop() {
copier.copy();
}
I was testing the result with an oscilloscope and I was getting the following:
This looks very promising indeed!
2 Comments
Martin · 30. July 2024 at 21:17
Is there a DAC inside? Or is this PWM and needs some low pass filter?
pschatzmann · 30. July 2024 at 21:20
This example uses the DAC.
The PWM example (which should work w/o filter) will be published next week….