2025-03-18 10:48 AM
Can someone help me with a clock configuration for STM32H7 with 8mhz crystal (I can change it if need) so I can get 0% drift for 44100Hz Audio?
Solved! Go to Solution.
2025-03-18 12:27 PM - edited 2025-03-18 12:40 PM
I think, you want not "drift", but just exactly 44k1 I2S frequency.
With a 8M source, it might be difficult to get it...i just tried, but no 100% match possible.
So other way:
But the 100% "simple, but clean" way is to use a crystal with an audio frequency, typical 16.9344 M or 11.2896 M. (384 or 256 x Fs 44k1)
If you can "live" with this (all clocks in cpu clock tree then "wrong", no clean 400MHz master clock, no easy 19200 serial connection possible....but "clean" 44k1 for I2S .
3rd way is to use the standard master clock and connect the I2S DAC as master, with its own 16.9344 M clock, i do it this way. But only possible, if the DAC or codec can be I2S master.
4rd way : the H743 ,( i use this), has an dedicated I2S clock input . (guess why ? standard problem for audio, to get the exact frequencies; so most "hi-end" devices go this way, just have 2 crystal oscillators , to switch between all 44k1 and 48k based frequencies)
So you could use a 16.9344 M or 11.2896 M oscillator, your "new master clock for audio" and connect it to the I2S clock-in :
The core, cpu, still on its standard 8M as it is...clock tree as you like it - just the SAI can run now on the audio master clock.
btw for I2S , use the SAI blocks, setting on I2S mode : they work perfect , better than the "I2S" on SPI .
2025-03-18 11:27 AM
There is no such thing as a clock with 0% drift. Manage your expectations accordingly. You should be able to find a crystal with +/- 20 ppm accuracy without much trouble. Depends what you are calling "drift" here as well.
2025-03-18 12:27 PM - edited 2025-03-18 12:40 PM
I think, you want not "drift", but just exactly 44k1 I2S frequency.
With a 8M source, it might be difficult to get it...i just tried, but no 100% match possible.
So other way:
But the 100% "simple, but clean" way is to use a crystal with an audio frequency, typical 16.9344 M or 11.2896 M. (384 or 256 x Fs 44k1)
If you can "live" with this (all clocks in cpu clock tree then "wrong", no clean 400MHz master clock, no easy 19200 serial connection possible....but "clean" 44k1 for I2S .
3rd way is to use the standard master clock and connect the I2S DAC as master, with its own 16.9344 M clock, i do it this way. But only possible, if the DAC or codec can be I2S master.
4rd way : the H743 ,( i use this), has an dedicated I2S clock input . (guess why ? standard problem for audio, to get the exact frequencies; so most "hi-end" devices go this way, just have 2 crystal oscillators , to switch between all 44k1 and 48k based frequencies)
So you could use a 16.9344 M or 11.2896 M oscillator, your "new master clock for audio" and connect it to the I2S clock-in :
The core, cpu, still on its standard 8M as it is...clock tree as you like it - just the SAI can run now on the audio master clock.
btw for I2S , use the SAI blocks, setting on I2S mode : they work perfect , better than the "I2S" on SPI .
2025-03-18 2:22 PM
Thanks AScha.3 this is what I was looking for. Do you have an example code source for SAI set on I2S mode? Are you intersted to help me with some solutions for STM32H7. I am ready to pay for your work.
2025-03-18 2:29 PM - edited 2025-03-18 5:34 PM
Resolved. Use SDMMC 2 and I2S_CKIN is free now
And I found a problem by using I2S clock input (your 4rd solution)... it is the same pin for SD Card D1 and I need SD card too. What I saw there is no alternative. Do you have any other idea?
2025-03-18 4:59 PM - edited 2025-03-18 5:33 PM
Already resolved this. Audio clock input it is in fact I2S_CKIN
One mroe question
Do you know what is the difference in Cube MX between Audio clock input and I2S_CKIN? Why appears both? There is a another special pin for Audio Clock input?
2025-03-19 7:45 AM
1. SDMMC not possible on all pins...if you want external I2S clock.
2. where are "both" ? There is only one external I2S clock , which is the audio clock then - if you choose it.
2025-03-19 8:22 AM
2025-03-19 8:36 AM
I don't know this particular H7, but those I know do have the FRACN registers for the PLL, which can be used for fine tuning.
Surely, you'll never get exactly 44.1 kHz, but you will also not get it exactly from most crystals / oscillators.
Last time I used FRACN / PLL for audio, the accuracy was about the same as with a 10 ppm crystal.
IMPORTANT: you need an external crystal / oscillator anyway, never use the HSI for audio, it's inaccurate and jitters like hell.