2023-10-25 12:50 PM - edited 2023-10-25 04:49 PM
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
2023-10-29 03:51 PM - edited 2023-10-29 07:43 PM
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.