cancel
Showing results for 
Search instead for 
Did you mean: 

SAI & I2S / DMA Callback imbalance - SAI Callbacks are called slightly more often than I2S Callbacks

AnkhInnovationsLLC
Associate III

Hello,

I have a strange issue here trying to read 2x PDM mics from the SAI peripheral and output the audio over the I2S peripheral here on the H7.

I use what appears to be the correct frequency for both peripherals and clear audio coming out, until the imbalance gets to be too much after some seconds. The SAI is called about 1.01 (approximately) times more often per second than the I2S peripheral. Cube MX shows a clock error of 0% for both.

The callback imbalance causes the audio to become distorted once the FreeRTOS queue is full. This queue currently just queues and de-queues items. It will later be used for processing of audio samples away from the DMA Callbacks. Whether this queue is in place or not, it doesn't make a difference. I count the difference in callbacks simply with a callbackImbalance variable, incrementing or decrementing it.

It's literally that HAL_SAI_RxCpltCallback (and half) is called slightly more often than HAL_I2SEx_TxRxCpltCallback (and half)

If I reduce or increase either clock, the amount of the callback imbalance is changed, however this doesn't seem like the right solution as I cannot get the imbalance to go away, just by guessing. The cocks seem to be exactly correct.

SAI: 2.048 Mhz, no divider (Decimation Ratio * Channels * Sample Rate) = 2048000
I2S: 2.048 Mhz, seems to divide internally as there is no settings for it in Cube MX

 

Screenshot 2023-10-25 at 12.40.13 PM.png

 

Screenshot 2023-10-25 at 12.49.34 PM.png

 

Screenshot 2023-10-25 at 12.50.05 PM.png

 

 

1 REPLY 1
AnkhInnovationsLLC
Associate III

Edit:

Finally figured this one out, it was another chip on the bus pulsing the I2S pin every so often that actually advanced the I2S peripheral slightly.