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
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?