Getting started with STM32L053: ADC Single Channel Continuous Conversion

In the previous guide (here), we took a look at how t configure the ADC of STM32L053 in single channel single conversion mode. In this guide, we shall see how to configure the ADC to work in continuous mode.

In this guide, we shall cover the following:

  • Difference between Single Conversion and Continuous Conversion.
  • What extra steps needed to enable continuous mode.
  • Results

1. Difference between Single Conversion and Continuous Conversion 

In the single conversion mode, the ADC does one conversion and stop as soon as the conversion ended. The process can’t started unless the start is triggered by software. This can be useful for certain application like monitor battery capacity like every 10 minutes. 

In continuous conversion mode, the ADC starts a new conversion as soon as it finishes one. This mode has the advantage of keeping the ADC value up to date for control purposes such as temperature, flow rate etc.

2. What the extra steps needed to enable Continuous Conversion

As we saw from the previous guide, we enabled the adc manually every time we needed to get a new adc value. To enable continuous mode, we need to enable CONT_bit (Bit 13) in ADC configuration register1 (ADC_CFGR1).

 /*Set Continuous conversion mode*/
	ADC1->CFGR1 |=ADC_CFGR1_CONT;

And in the main function,

#include "uart.h"
#include "adc.h"
#include "stdio.h"
uint32_t adc_data;
int main(void)
{
	pa1_adc_init();
	adc_activate();
	uart_init();
	start_conversion();
	while(1)
	{

		adc_data=adc_read();
		printf("adc data=%ld\r\n",adc_data);
		for (int i=0;i<1000;i++);


	}

}

As you may noticed, the start conversion is called once and the conversion will occur automatically:

3. Results:

Open a serial terminal and set the baud rate at 9600 and you will get the following:

Happy coding 🙂

Add Comment

Your email address will not be published. Required fields are marked *