cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F205 temperature sensor problems

tfk
Associate II
Posted on June 24, 2011 at 15:06

Hi everybody,

I'm having some trouble with the STM32F205 temperature sensor. 

I'm using the algorithm from section 10.10 in the reference manual. {(V25 � VSENSE) / Avg_Slope} + 25

I'm using the following algorithm to convert the ADC value to a voltage value from the temperature sensor ADC channel (ch 16):

ADCConvertedValue*3.3/4096;

When I'm heating up the chip the ADCConvertedValue increases resulting in a greater voltage value, that results in lower temperature as a higher VSENSE value will subtract more from V25. 

Does anyone have the same problem ? 

Best Regards

Tord

#not-that-complicated #vsense-temperature-sensor #adc-dma #stm32f205-temperature
20 REPLIES 20
cristian2399
Associate II
Posted on June 29, 2012 at 15:37

Hi this is mai code:

#define STM32_TEMPSENS_ADC_DEVICE                ADC1

#define STM32_TEMPSENS_ADC_IRQHANDLER            ADC_IRQHandler

#define STM32_TEMPSENS_ADC_IRQCHANNEL            ADC_IRQn

#define STM32_TEMPSENS_ADC_PERIPH_CLK            RCC_APB2Periph_ADC1

#define STM32_TEMPSENS_ADC_PERIPH_CLK_FREQ_HZ    (PROJECT_SYSCLK_HZ / 2)

#define STM32_TEMPSENS_ADC_PRESCALER            8

#define STM32_TEMPSENS_ADC_RESOL_BITS            12

#define STM32_TEMPSENS_ADC_SAMPLETIME_CYCLES    56

#define STM32_TEMPSENS_ADC_V_REF_4DD            33000 /* typical */

#define STM32_TEMPSENS_AVG_SLOPE_MV_DEGC_1DD    25    /* typical */

#define STM32_TEMPSENS_V_25DEGC_4DD                7600  /* typical */

#define STM32_TEMPSENS_T_S_US                    10    /* typical */

#define STM32_TEMPSENS_ADC_RESOL_STEPS    (1 << STM32_TEMPSENS_ADC_RESOL_BITS)

static volatile uint16_t tempsens_rawval;

static volatile uint8_t conv_running;

static int

_init(const struct w2h_dev_t *self, const void *cfg)

{

    ADC_InitTypeDef ADC_InitStructure;

    ADC_CommonInitTypeDef ADC_CommonInitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable STM32_TEMPSENS_ADC_DEVICE clock. */

    (void)self;

    (void)cfg;

    RCC_APB2PeriphClockCmd(STM32_TEMPSENS_ADC_PERIPH_CLK, ENABLE);

    /* Configure NVIC for STM32_TEMPSENS_ADC_DEVICE. */

    NVIC_InitStructure.NVIC_IRQChannel = STM32_TEMPSENS_ADC_IRQCHANNEL;

    NVIC_Init(&NVIC_InitStructure);

    tempsens_rawval = 0;

    ADC_DeInit();

    /* ADC Common Init */

    ADC_CommonStructInit(&ADC_CommonInitStructure);

    ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

    ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div8;

    ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

    ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

    ADC_CommonInit(&ADC_CommonInitStructure);

    /* STM32_TEMPSENS_ADC_DEVICE configuration. */

    ADC_StructInit(&ADC_InitStructure);

    ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

    ADC_InitStructure.ADC_ScanConvMode = DISABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

    ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

    /* ADC_InitStructure.ADC_ExternalTrigConv = xxx; */

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfConversion = 1;

    ADC_Init(STM32_TEMPSENS_ADC_DEVICE, &ADC_InitStructure);

    /* STM32_TEMPSENS_ADC_DEVICE temperature sensor configuration. */

    /* The temperature sensor requires a sample time of at least 17.1 us. */

    /*

     * With ADC clock @12 MHz (PCLK2 / 6) and a sample time of 239.5 cycles,

     * the temperature sensor's required sample time can be matched.

     */

    ADC_RegularChannelConfig(STM32_TEMPSENS_ADC_DEVICE, ADC_Channel_TempSensor,

                             1, ADC_SampleTime_480Cycles);

    /* Enable temperature sensor and Vref. */

    ADC_TempSensorVrefintCmd(ENABLE);

    /* Enable STM32_TEMPSENS_ADC_DEVICE EOC interupt. */

    ADC_ITConfig(STM32_TEMPSENS_ADC_DEVICE, ADC_IT_EOC, ENABLE);

    /* Enable STM32_TEMPSENS_ADC_DEVICE. */

    ADC_Cmd(STM32_TEMPSENS_ADC_DEVICE, ENABLE);

    printfx(''call adc_init\n'');

    return W2H_ERR_OK;

}

static int

_deinit(const struct w2h_dev_t *self)

{

    (void)self;

    return W2H_ERR_OK;

}

static int

_read(const struct w2h_dev_t *self,  uint16_t *ptr)

{

    int32_t val;

    (void)self;

    /* Argument checks. */

    if (ptr == NULL) {

        return 1;

        /* NOTREACHED */

    }

    conv_running = 1;

    /* Start next STM32_TEMPSENS_ADC_DEVICE Software Conversion. */

    ADC_SoftwareStartConv(STM32_TEMPSENS_ADC_DEVICE);

    /* Loop until ISR has finished. */

    while (conv_running != 0) {

        /* Wait (do nothing). */

    }

    /* Convert ADC result to value in degC. */

    val = ((int32_t)tempsens_rawval * STM32_TEMPSENS_ADC_V_REF_4DD)

          / (STM32_TEMPSENS_ADC_RESOL_STEPS - 1);

    val = STM32_TEMPSENS_V_25DEGC_4DD - val;

    val /= STM32_TEMPSENS_AVG_SLOPE_MV_DEGC_1DD;

    val += 25;

    *ptr = val;

    return W2H_ERR_OK;

}

void w2h_stm32_adc_ev_irqh(const struct w2h_dev_t *self)

{

    (void)self;

    if (ADC_GetITStatus(STM32_TEMPSENS_ADC_DEVICE, ADC_IT_EOC) != RESET) {

        /*

         * The ''End of conversion'' bit (EOC) -- as the interrupt source --

         * is cleared by reading ADC_DR.

         */

        tempsens_rawval = ADC_GetConversionValue(STM32_TEMPSENS_ADC_DEVICE);

        conv_running = 0;

    }

}

And the problem is that, I am reading the same

conts = 0x3C4;  5 counts tolerance

Normaly, I think that even touching the uC, with my finger the conts should take other value.

I tried desabling the temp Vref, and I read:

conts =  0x05;  3 conts tolerance

I have tried spray the processor with an alcohool spray (-52 C deg), and I read more conts. Probably becouse of the variation, of internal reference.

Thank You for answer.

cm600
Associate II
Posted on June 29, 2012 at 20:45

Temperature (in °C) = {(VSENSE– V25) / Avg_Slope} + 25

The formula was wrong in the earliest versions of the ref. manual.

raptorhal2
Lead
Posted on June 29, 2012 at 22:55

And, remove the comment marks in

 /* ADC_InitStructure.ADC_ExternalTrigConv = xxx; */

and set xxx = 0.

Let us know what happens after these fixes.

Cheers, Hal

cristian2399
Associate II
Posted on July 02, 2012 at 08:39

Hello all,

It seems that i had only a conversion problem, in converting conts to temp.

Thank you Valentin for formula correction.

However I'm still not quite not happy, with what I obteined. Measuring the temp sensor once per second, I have jumps eaven of 2 C deg.

Although the ADC clock is divided by 8 and ADC_SampleTime_480Cycles, it seems a little bit strage for me.

Thank you for feedback,

Cristian

ColdWeather
Senior
Posted on July 02, 2012 at 09:50

> Temperature (in °C) = {(VSENSE– V25) / Avg_Slope} + 25

The equation above must be WRONG. The latest RM says:

{(V25 - VSENSE) / Avg_Slope} + 25

and it works on my boards (a part of the code):

    float

 

    _Vsense =  1.0 * ADC_ValueToVoltage(ADC_Values[0]);

 

    return (_V25 - _Vsense)*1000/_Slope + 25;    // ...and add 25^C

 

cristian2399
Associate II
acihana
Associate II
Posted on April 01, 2015 at 16:48

I have the same problem. I can read only one fixed value from temperature sensor after power-on. I've tried a lot of code, including the above examples. Using DMA, without DMA, interrupt, polling.. no way. I can read just only one value despite of heating/cooling the processor. It seems like the ''continuous converting mode'' is in trouble. As a said, I've tried all configurations. My last trial code;

(for stm32f205!)

void ADC_init(void){

    ADC_InitTypeDef       ADC_InitStructure;

    ADC_CommonInitTypeDef ADC_CommonInitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    DMA_InitTypeDef DMA_InitStructure;

    DMA_StructInit(&DMA_InitStructure);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);

    DMA_InitStructure.DMA_Channel = DMA_Channel_0;

    DMA_InitStructure.DMA_BufferSize = 2;                    

    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;    

    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;    

    DMA_InitStructure.DMA_FIFOThreshold = 0;

    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;          

    DMA_InitStructure.DMA_Priority = DMA_Priority_High;       

 

    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)ADCBuffer; 

    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; 

    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

    /* config of peripheral */

    DMA_InitStructure.DMA_PeripheralBaseAddr = &ADC1->DR; 

    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

    DMA_Init(DMA2_Stream0, &DMA_InitStructure); 

    DMA_Cmd(DMA2_Stream0, ENABLE);

    ADC_StructInit(&ADC_InitStructure);

    ADC_CommonStructInit(&ADC_CommonInitStructure);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

    ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

    ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

    ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

    ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

    ADC_CommonInit(&ADC_CommonInitStructure);

    ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

    ADC_InitStructure.ADC_ScanConvMode = ENABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

    ADC_InitStructure.ADC_ExternalTrigConvEdge = 0;

    ADC_InitStructure.ADC_ExternalTrigConv = 0;

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfConversion = 2;

    ADC_Init(ADC1, &ADC_InitStructure);

    ADC_TempSensorVrefintCmd(ENABLE);

    ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_480Cycles);

    /* VREF_int (2nd) */

    ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 2, ADC_SampleTime_480Cycles);

    /* Enable ADC interrupts */

    ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

    /* Enable DMA request after last transfer (Single-ADC mode) */

    ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);

    /* Enable ADC3 DMA */

    ADC_DMACmd(ADC1, ENABLE);

    /* Configure NVIC */

    NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;

    NVIC_Init(&NVIC_InitStructure);

    /* Enable ADC1 **************************************************************/

    ADC_Cmd(ADC1, ENABLE);

}

void adc_ev_irqh(void){

ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);

}

I can see both Vref and Temp values via serial port. There's no change after power-on, but the values are changing at each restart..

Posted on April 01, 2015 at 18:28

This seemed to work first time without any issues, should be fine on the F2, also use the DMA TC for the EOC

// STM32 ADC Sample Vref and Temp STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
}
/**************************************************************************************/
void ADC_Configuration(void)
{
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
/* ADC Common Init */
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE; // 2 Channels
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // Continuous Conversions
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO; // Ignored
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 2;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_480Cycles); // TEMP 16 on 40x/41x, 18 on 42x/43x
ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 2, ADC_SampleTime_480Cycles); // VREFINT
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
}
/**************************************************************************************/
#define BUFFERSIZE 2
__IO uint16_t ADCConvertedValues[BUFFERSIZE];
static void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCConvertedValues[0];
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = BUFFERSIZE; // Count of 16-bit words
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
/* Enable DMA Stream Transfer Complete interrupt */
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);
/* DMA2_Stream0 enable */
DMA_Cmd(DMA2_Stream0, ENABLE);
}
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the DMA Stream IRQ Channel */
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
void DMA2_Stream0_IRQHandler(void)
{
/* Test on DMA Stream Transfer Complete interrupt */
if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
/* Toggle LED3: End of Transfer */
STM_EVAL_LEDToggle(LED3);
// Add code here to process buffer
}
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
DMA_Configuration();
ADC_Configuration();
STM_EVAL_LEDInit(LED3); /* Configure LEDs to monitor program status */
STM_EVAL_LEDOn(LED3); /* Turn LED3 on */
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConv(ADC1);
while(1); // Don't want to exit
}
/**************************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**************************************************************************************/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
acihana
Associate II
Posted on April 02, 2015 at 10:55

Thank you for your answer Clive, but still I have the same problem. I read different values for each restart and these values remain unchanged.. Here's my code;

void ADC_init(void){ /* Define ADC init structures */

    ADC_InitTypeDef       ADC_InitStructure;

    ADC_CommonInitTypeDef ADC_CommonInitStructure;

    DMA_InitTypeDef DMA_InitStructure;

     DMA_InitStructure.DMA_Channel = DMA_Channel_0;

     DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCConvertedValues[0];

     DMA_InitStructure.DMA_PeripheralBaseAddr = ((uint32_t)0x4001204C);//(uint32_t)&ADC1->DR;

     DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

     DMA_InitStructure.DMA_BufferSize = BUFFERSIZE; // Count of 16-bit words

     DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

     DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

     DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

     DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

     DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

     DMA_InitStructure.DMA_Priority = DMA_Priority_High;

     DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;

     DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;

     DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

     DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

     DMA_Init(DMA2_Stream0, &DMA_InitStructure);

     /* Enable DMA Stream Transfer Complete interrupt */

     DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);

     /* DMA2_Stream0 enable */

     DMA_Cmd(DMA2_Stream0, ENABLE);

     /* ADC Common Init */

ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

ADC_CommonInit(&ADC_CommonInitStructure);

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ScanConvMode = ENABLE; // 2 Channels

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // Continuous Conversions

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO; // Ignored

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfConversion = 2;

ADC_Init(ADC1, &ADC_InitStructure);

/* ADC1 regular channel configuration */

ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_480Cycles); // TEMP 16 on 40x/41x, 18 on 42x/43x

ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 2, ADC_SampleTime_480Cycles); // VREFINT

//ADC_TempSensorVrefintCmd(ENABLE);

/* Enable DMA request after last transfer (Single-ADC mode) */

ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);

/* Enable ADC1 DMA */

ADC_DMACmd(ADC1, ENABLE);

/* Enable ADC1 */

ADC_Cmd(ADC1, ENABLE);

}

void DMA2_Stream0_IRQHandler(void)

{

  /* Test on DMA Stream Transfer Complete interrupt */

  if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))

  {

    /* Clear DMA Stream Transfer Complete interrupt pending bit */

    DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);

    /* Toggle LED3: End of Transfer */

toggle_leds(LED_2);

AD_value = ADCConvertedValues[0];

    // Add code here to process buffer

  }

}

main;

int main(void){

u32 i;

SystemInit();

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA2, ENABLE);

//RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1|RCC_APB1Periph_USART2|RCC_APB1Periph_TIM3, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_ADC1, ENABLE);

for(i = 0 ; i < 1000000; i++); // a delay, may be useful

NVIC_Config();

LEDS_init();

OUTPUTS_init();

INPUTS_init();

FPGA_pins_init();

//USART2_init(115200);

//i2c_init();

ADC_init();

for(i = 0 ; i < 1000000; i++);

DAC8411_init();

TIM3_init();

SysTick_Config(SystemCoreClock / 1000);

initilize_variables();

bessel_filter_coeffs();

butterworth_filter_coeffs();

calibrated_filter_type = NO_FILTER;

raw_data_filter_type = NO_FILTER;

ADC_SoftwareStartConv(ADC1);

while(1){

......... lots of things

}

}

jpeacock
Associate III
Posted on April 02, 2015 at 17:07

If your value isn't changing most likely you are getting an error in either the ADC or DMA.  Check your ADC status, especially the EOC to see if you started a conversion, and the overflow flag to check for dropped data.  You won't see data change if you aren't converting.

On the DMA side check the TE and FE flags for errors.  Your data won't change if DMA is stopping.

  Jack Peacock