Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

stm32 problem with ADC conversion

Status
Not open for further replies.

mikewax

Newbie level 4
Joined
Feb 21, 2017
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
38
can someone check my setup please? in line 1 the MCU, an stm32F070RB, does a conversion and in line 5 it does another one. but the second conversion fails and the program hangs up at line 7. if i suppress line 7 the program will continue uninterrupted.
the ADC register values are shown below.
Code:
1 ADC1->CR |= (uint32_t)ADC_CR_ADSTART;  // start first conversion
2 count = 0;
3 while(((ADC1->ISR & ADC_ISR_EOC) == (uint32_t)reset) && (count < timeout)) count++; // wait for end of conversion
4 capVL = (uint16_t)ADC1->DR;  // read value
5 ADC1->CR |= (uint32_t)ADC_CR_ADSTART;  // start second conversion
6 count = 0;
7(//) while(((ADC1->ISR & ADC_ISR_EOC) == (uint32_t)reset) && (count < timeout)) count++;
8 capVH = (uint16_t)ADC1->DR;  // read value
ADCregs.png
 

You can try giving some delay between first conversion and start of second conversion.
 

You can try giving some delay between first conversion and start of second conversion.
Worse advise of the day.

For STM32F0x0:
Code:
#define TS_CAL1									*(__IO int16_t*)0x1FFFF7B8
#define TS_CAL2									*(__IO int16_t*)0x1FFFF7C2
#define VREFINT_CAL							*(__IO int16_t*)0x1FFFF7BA

uint32_t ADCx_GetCalibrationFactor (ADC_TypeDef * ADCx)
{
	ADCx->CR |= ADC_CR_ADCAL;
	while(ADCx->CR & ADC_CR_ADCAL);
	
	return ADCx->DR;
}

float GetIntTemp (void)
{
	float res;
	
	ADC1->CHSELR = ADC_CHSELR_CHSEL16;
	ADC1->SMPR = ADC_SMPR_SMP;
	ADC->CCR |= ADC_CCR_TSEN;
	ADC1->CR = ADC_CR_ADSTART | ADC_CR_ADEN;
	while (!(ADC1->ISR & ADC_ISR_EOC));
	
	res = (110.0 - 30.0) * (float)((int16_t)ADC1->DR - TS_CAL1) / (float)(TS_CAL2 - TS_CAL1) + 30.0;
	
	ADC->CCR &= ~ADC_CCR_TSEN;
	ADC1->CR = 0;
	
	return res;
}

float GetIntVDD (void)
{
	float res;
	
	ADC1->CHSELR = ADC_CHSELR_CHSEL17;
	ADC1->SMPR = ADC_SMPR_SMP;
	ADC->CCR |= ADC_CCR_VREFEN;
	ADC1->CR = ADC_CR_ADSTART | ADC_CR_ADEN;
	while (!(ADC1->ISR & ADC_ISR_EOC));
	
	res = 3.3 * (float)VREFINT_CAL / (float)ADC1->DR;
	
	ADC->CCR &= ~ADC_CCR_VREFEN;
	ADC1->CR = 0;
	return res;
}

uint16_t ADC_GenericRead (ADC_TypeDef * ADCx, uint32_t ADC_Channel)
{
	ADCx->SMPR = 7;
	ADCx->CHSELR = ADC_Channel;
	ADCx->CR = ADC_CR_ADEN | ADC_CR_ADSTART;
	while(!(ADCx->ISR & ADC_ISR_EOC));
	return ADCx->DR;
}
 
thanx EasyRider for the code i'll try it and we'll see.:thumbsup:
 

well i will use your code in the future it's much better than the code i'm using.
fortunately the problem dissapeared and i never found out what was wrong. live and learn.:thumbsup:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top