cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f207 ADC+TIMER+DMA / Poor Peripheral Library Examples

adrian
Associate III
Posted on April 24, 2013 at 11:19

Hi,

I'm looking to sample a signal (well, 2 actually - quadrature analog signals) at a fixed sample rate, but I'm baffled by the lack of any example in the Standard Peripheral Library on how to achieve this.

I would have thought that this would be a pretty standard example, i.e sample x points of a signal at y kHz and store result in memory location z.

Can anyone from ST comment on why such a basic (and imo fundamental) example is missing from the Standard Peripheral Library?

Does anybody else have an basic example of how this is achieved?  There are various incomplete snippets of code if you search in this forum, but elsewhere on the internet I've been able to find zilch.

I suspect I'm going to have to go read the manual in depth to figure this lot out...oh joy!

Many thanks.

Adrian
34 REPLIES 34
Posted on August 30, 2015 at 16:38

It should decimate. Pairs of samples, interrupting halfway through as it fills each half.

So 800 sample buffer / (2 * 2) = 200 sample pairs between interrupts

200 KHz / 200 sample periods = 1 KHz

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
galamat
Associate II
Posted on November 13, 2015 at 18:40

Hi!

I wrote code, but it stuck inADC_GetStatus(ADC1). Could someone help me?

________________

Attachments :

adc.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0q9&d=%2Fa%2F0X0000000beJ%2FlEMPW7LxCO96c_2NpElozBrofR_TW_hlu6ofZ5JejGA&asPdf=false
galamat
Associate II
Posted on November 13, 2015 at 18:42

Problem, I stuck in ADC_GetStatus(ADC1).

#include <stm32l/rcc.h>

#include <stm32l/nvic.h>

#include <stm32l/gpio.h>

#include <stm32l/stm32l.h>

#include <stm32l/exti.h>

#include <stm32l/syscfg.h>

#include <stm32l/adc.h>

#define BUFFERSIZE 1000

 

/**************************************************************************************/

void simple_delay(uint32_t us)

{

/* simple delay loop */

while (us--) {

asm volatile (''nop'');

}

 

 

void RCC_Configuration(void)

{

  RCC_AHBPeriphClockCmd(AHB_GPIOA, ENABLE);

  RCC_APB2PeriphClockCmd(APB2_ADC1, ENABLE);

  RCC_AHBPeriphClockCmd(AHB_GPIOB, ENABLE);

}

 

/**************************************************************************************/

 

void GPIO_Configuration(void)

{

 

 

  /* ADC Channel 2 -> PA2 */

gpio_init_t gpio;

GPIO_StructInit(&gpio);

gpio.pins = GPIO_P2; //pin A2

gpio.mode = GPIO_ANALOG;      //analog

gpio.pupd = GPIO_P_NOPULL;     // no pull

/* apply configuration */

GPIO_Init(GPIOA, &gpio);

gpio_init_t gpio1;

GPIO_StructInit(&gpio1);

gpio1.pins = GPIO_P7;

gpio1.mode = GPIO_OUTPUT;

gpio1.otype = GPIO_OT_PP;

GPIO_Init(GPIOB, &gpio1);

 

}

 

/**************************************************************************************/

 

void ADC_Configuration(void)

{

adc_init_t adc;

adc_init_com_t adc_com;

ADC_CommonStructInit(&adc_com);

ADC_StructInit(&adc);

 /* ADC Common Init */

adc_com.prescaler=ADC_PRESCALER_DIV4;

ADC_CommonInit(&adc_com);

adc.resolution = ADC_RESOLUTION_12b;

adc.scan_conv_mode = DISABLE; // 1 Channel

adc.continuous_conv_mode = DISABLE; // Conversions Triggered

adc.external_trig_conv_edge = ADC_EXTTRIGCONVEDGE_RISING; // Manual

adc.external_trig_conv = ADC_EXTTRIGCONV_T2_TRGO;

adc.data_align = ADC_DATAALIGN_RIGHT;

adc.conversion_num = 1;

ADC_Init(ADC1,&adc);

  /* ADC1 regular channel 11 configuration */

ADC_RegularChannelConfig(ADC1, ADC_C2, 1, ADC_SAMPLETIME_4C); // PC1 

  /* Enable ADC1 */

ADC_Cmd(ADC1, ENABLE);

}

 // blinking

 void led_blink(){

GPIO_SetPins(GPIOB, GPIO_P7);

/* delay */

simple_delay(100000);

/* clear led */

GPIO_ClearPins(GPIOB, GPIO_P7);

/* delay */

simple_delay(100000);

}

 

 

/**************************************************************************************/

 

 

uint16_t ADCConvertedValues[BUFFERSIZE];

uint32_t ADCStat = 0x0;

 

int main(void)

{

uint16_t reg;

int i;

RCC_DeInit();

    RCC_Configuration(); 

    GPIO_Configuration(); 

ADC_Configuration();

 

i = 0;

 

GPIO_SetPins(GPIOB, GPIO_P7);

simple_delay(1000000);

GPIO_ClearPins(GPIOB, GPIO_P7);

simple_delay(1000000);

ADC_SoftwareStartConv(ADC1);

if(ADC_GetSoftwareStartConvStatus(ADC1)){

GPIO_SetPins(GPIOB, GPIO_P7);

}

    while((ADC_GetStatus(ADC1)&0x2)==0);

GPIO_ClearPins(GPIOB, GPIO_P7);

    ADCConvertedValues[i++] = ADC_GetConversionValue(ADC1);

    i %= BUFFERSIZE;

    while(1) // Don't want to exit

    {

  

    

  }

}

Posted on November 13, 2015 at 19:55

When you are using an STM32 part that's unrelated to the thread's stated topic please open a new thread about your question and problem.

I'm not familiar with the library you are using, it seems to be a mix of SPL with something else. Please state clearly what you're using. The L1 needs the HSI clock enabled for the ADC to function.

/* Enable The HSI (16Mhz) */
RCC_HSICmd(ENABLE);
/* Check that HSI oscillator is ready */
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 13, 2015 at 19:59

This first one is an on-topic, on-point thread

https://community.st.com/0D50X00009XkiMhSAJ

 

 

Edit: Fixed DEAD LINKs

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..