In my last blogs, I introduced you to the powerfull STM32H743VIT6 microcontroller and demonstrated the analog and PWM audio output using the Arduino Audio Tools library.
I finally managed to extend the stm32-i2s library and so it the time now that I can demonstrate that we can also use I2s as well:
I am using the demo sketch from the AudioTools w/o any changes:
#include "AudioTools.h"
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000);
GeneratedSoundStream<int16_t> sound(sineWave);
I2SStream out;
StreamCopy copier(out, sound);
// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
//while(!Serial);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
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();
}
Dependencies
The sketch above relies on the following I2S library: https://github.com/pschatzmann/stm32-i2s that needs to be installed separately.
The pins are defined in src/stm32-config-i2s.h:
{mclk, PC_7, GPIO_AF6_SPI3},\
{bck, PC_10, GPIO_AF6_SPI3},\
{ws, PA_4, GPIO_AF6_SPI3},\
{data_out, PC_12, GPIO_AF6_SPI3},\
Result
The sketch compiles w/o error messages and gives the following information
Sketch uses 81032 bytes (3%) of program storage space. Maximum is 2097152 bytes.
Global variables use 6344 bytes (1%) of dynamic memory, leaving 517944 bytes for local variables. Maximum is 524288 bytes.
Here is result from an oszilloscope for the clock and data out pins:
The library seems to work and we are getting the expected I2S signal!
0 Comments