2024-08-21 11:21 PM
Hi all,
I reach out to you all to give some pointers or advice for me where to look into to solve this mystery.
I set up my Nuc-STM32F439ZI eval board i2s peripheral to play my audio sine wav file.
I used Audacity to generate 13KHz sine wave audio file with 48KHz sampling, 16-bit PCM wav file, then using Wav2Code to generate the array binary.
For STM32, I set I2S with 48KHz Sampling rate, Half-Duplex Master, Mode Master Transmit, I2S Philips, 16 bits data on 16 bits frame, DMA half word, Circular mode.
I2S generated correct signal, bit clock, frame rate, data valid but when I feed this sine wave to an amplifier and monitor the output of the amplifier on the scope, I saw my sine wave double in frequency which is 22KHz to 26KHz.
I then tried different way to create the sine wave with the look up table from the sine wave math function with the frequency of 1KHz, and the result is the same at the amplifier output, I got 2KHz sine wave.
Does anyone else this behavior or anything you experienced?
Solved! Go to Solution.
2024-08-26 10:34 AM
Thank you both @waclawek.jan and @MM..1 for your pointers.
I got the correct sine wave output as my source with the same frequency. It is all from I2S needs to have the sample buffer = 2x my source sample buffer.
So for anyone interested the way to create a sample_buffer array using Audacity + WAVToCode
After step#2 above, we need to double it by this pseudocode from JW
uint16_t sample_buf[nrOfSamples * 2];
for (i = 0; i < nrOfSamples; i++) {
buf[2 * i] = original_data(i);
buf[2 * i + 1] = original_data(i);
}
Step#4: Once the I2S is done set up, you only need to call HAL_I2S_Transmit_DMA(&hi2s2, sample_buf, nrOfSamples * 2) once if you would like the code generate one frequency one amplitude of the output wave.