2021-03-08 12:13 AM
I have a sensor with analog data and I am connecting it to one of the ADC pins (STM32L152). I have no problem to read a single conversion data. However, I would like to one shot capture multiple ADC data (for example, 128) so it will be more consistent in terms of sampling rate.
Which mode should I use and do we have an example for it?
Thanks!
2021-03-08 12:27 AM
> However, I would like to one shot capture multiple ADC data (for example, 128) so it will be more consistent in terms of sampling rate.
Then, continuous mode is not the way to go. This is just an endless sequence of back-to-back conversions.
Use a timer as trigger to establish the proper sampling rate, and preferably DMA to retrieve the results.
DMA can be setup to any size up to 64kByte, so 128 values is perfectly fine.
I had done this with a F407 and F303 multiple times, but have no L152 example, though.
Perhaps Cube/HAL generated, albeit I would not really recommend it ...
2021-03-08 04:29 AM
Thanks! I thought there will be a way to capture multiple data (stored at buffer/DMA) and each data is sampled at X kHz. But, it seems like I will have to use the timer.
2021-03-08 05:02 AM
That's basically what happens.
You set up the timer, and start it when you are ready.
You set up DMA for a specific number of samples (e.g. 128 words = 256 bytes), and a TC interrupt (transmission complete).
Then you get a DMA-TC interrupt every time another buffer of 128 values is ready.
The sampling rate itself is determined by the timer.
With continuous mode, you could only adjust the timing via sampling time settings.
Check the datasheet / reference manual for timers and DMA channels appropriate for working with the ADC.
I didn't do many projects on the L152, though.
2021-03-08 05:16 AM
Thanks! How do you set the DMA for a specific number of samples. Any particular function?