Skip to main content
Graduate
March 18, 2025
Solved

Clock configuration for I2S audio for STM32H7A3

  • March 18, 2025
  • 3 replies
  • 1421 views

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?

 

 

 

    This topic has been closed for replies.
    Best answer by AScha.3

    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 :

    AScha3_0-1742325917940.png

    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 .

    3 replies

    Super User
    March 18, 2025

    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.

    AScha.3Answer
    Super User
    March 18, 2025

    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 :

    AScha3_0-1742325917940.png

    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 .

    laurianusAuthor
    Graduate
    March 18, 2025

    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. 

     

     

    Graduate II
    March 19, 2025

    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.