2021-07-30 02:06 AM
Hello,
I'm using an stm32l151re to interface with mp34dt05-a mems microphone. I'm using it to determine noise level. The communication between smt32 mcu and the sensor is based on I2S protocol with dma. My issue is that my project consists of multiple tasks and I added an audio task to process data in order to determine the noise level but the dma buffer keeps updating the dma buffer before I finish processing the first half buffer.
The dma interrupt occurs each 1ms and the process function takes 800us to process the data from the sensor. How can I make sure that I process new data before receiving a new one.
thanks in advance for your suggestions
2021-08-05 02:21 AM
Using 800us out of 1ms for date processing is alot, especially when you talk about multiple (RTOS?) tasks. If the additional delay is of no/little concern, I would increase the buffer sizes by a factor of at least 10 or so to average out short overloads. In addition, a buffer queue could be useful which decouples the producer (irq) from the consumer (data processing). With circular DMA this can be done using another DMA copying the just recorded buffer to a safe place in a ring buffer queue. Double buffering DMA would be better, but is not avail on your chip.
To observe buffer over/underruns, you can mark the first word(s) in the DMA buffer with some magic values (e.g. extrema) and later check if they were overwritten by DMA hardware.
Finally: is it really neccessary to process each and every audio sample for noise detection? Think of linear DMA wich is triggered by some timer every 1,2ms buying you more headroom for processing+aux. tasks or by skipping a buffer every now and then when you detected an overflow.
2021-08-27 06:07 AM
Thanks for your reply. It's very enlightening. I'll make sure to try this out.