cancel
Showing results for 
Search instead for 
Did you mean: 

Why is the SAI (I2S) used in DMA mode generate noise

eeprom
Associate II

I am using a SAI device on a SMT32WB55. Using it as a wavetable synth that produces a triangle wave.

I am able to play my triangle wave for x amount of time with

HAL_SAI_Transmit_DMA(&hsai_BlockA1, (uint8_t*)data, size);

And later stop it with a timer using :

HAL_StatusTypeDef status = HAL_SAI_DMAStop(&hsai_BlockA1);

Whichever frequency I use for my triangle wave, the sound is fine. However, if I play another note after the first one, I can ear so pop/clicks/tearing that gets worst after each note. If I play diferent notes, I can still hear a trail of the previous note before the right frequency kicks in.

Everything is reset in the triangle wave generator after each note and the array assigned to the dma circular buffer in the transmit function is memset to 0 just in case.

After inspecting the HAL code for the HAL_SAI_DMAStop function, I can see that the dma requests are stopped and the fifo is cleared. So there should be no residual data when DMAStop is called.

Is there something I am missing?

Thank you.

3 REPLIES 3

Don't you rewrite the table while DMA is still running?

Observe the analog output using oscilloscope, perhaps post waveform.

JW

eeprom
Associate II

I am rewriting the table using tx complete and tx half complete interrupts so I can keep generating the sound from my waveform continuously. I just tried to set the buffer to 0 and keep the SAI dma playing and the result is what I would like to have. No glitching in the sound.

However, I suspect that using HAL_SAI_DMAStop would be a wiser choice energy wise.

I do not have a scope, but I do have a logic analyzer. I am not sure how to interpret what I see on the bus and cannot trigger and log enough samples to get the whole sequence.

Thank you.

eeprom
Associate II

Here are some logic analyzer captures that highlights a clear behaviour change.

Notice that the Left and Right channels are getting the same value when I am letting the sai device roll on dma and just setting the buffer to 0 to stop playing (sound is being played during the capture):

0693W00000Y88smQAB.png 

And when I am simply adding the HAL_SAI_DMAStop function call, things get weird, there seems to be some mismatch between right and left channel values (I am using I2S in mono mode):

0693W00000Y88u4QAB.pngHere is my SAI device configuration:

0693W00000Y8DWvQAN.png