Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Multichannel ADC using DMA on STM32

Last time we have tried to do a single conversion of one channel. We were waiting for the result in a loop which isn’t an effective way of using processor resources. It is better to trigger conversion and wait for conversion complete interrupt. During this time processor can do other tasks rather than wait for ADC conversion complete. So this time we will go through another example where we will set up more than one channel and read ADC values within interrupt service routine. If we need to convert several channels continuously, we need to set up Sequence registers (ADC_SQRx). There are three sequence registers: ADC_SQR1, ADC_SQR2, and ADC_SQR3 where we can set up a maximum of 16 channels in any order. Conversion sequence starts with SQ1[4:0] settings in ADC_SQR3… Continue reading

Using Direct Memory Access (DMA) in STM32 projects

In many microcontroller projects, you need to read and write data. It can be reading data from the peripheral unit like ADC and writing values to RAM. In another case maybe you need to send chunks of data using SPI. Again you need to read it from RAM and continuously write to SPI data register and so on. When you do this using processor – you lose a significant amount of processing time. To avoid occupying CPU most advanced microcontrollers have Direct memory Access (DMA) unit. As its name says – DMA does data transfers between memory locations without the need of CPU. Low and medium density ST32 microcontrollers have a single 7 channel DMA unit while high-density devices have two DMA controllers with 12 independent channels. In STM32VLDiscovery their… Continue reading