Hello everyone, I need to use the ADC interupt on my stm32p103, with two Ultra Sound sensor.
I need the data to be read on continuous mode, and detect a threshold crossing
I use the following configuration:
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 2; //1by sensor
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_239Cycles5);
/* Enable EOC interupt */
ADC_ITConfig(ADC1,ADC_IT_EOC, ENABLE);
ADC_Cmd(ADC1, ENABLE); //must be called after all other ADC configuration functions.
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void ADC1_2_IRQHandler(void)
{
DataValue = ADC_GetConversionValue(ADC1);
if(DataValue<80) //résolution du dac=2^12=4096
clearLed;
else
setLed;
/* Clear ADC1 EOC pending interrupt bit */
ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
}
I Use the value 80, because my sensor detects objects on a range from 0 to 0.2V.
I wonder how to recover the two different value from ADC_Channel_10 and ADC_Channel_11 separatly.
Thaks for your help!
|
Hi,
Please take a look at the examples from the ST library, there is one example that will show you how to do it. It uses DMA to place the values from the channels in separate RAM locations.
Best Regards,
Is it's relly necessarly to use the DMA for the conversion? because there's an exemple without it.