cancel
Showing results for 
Search instead for 
Did you mean: 

USB internal pull-up - stop - ADC

michelemancini2
Associate III
Posted on June 21, 2014 at 09:41

Hi, I have a problem with  STM32L151xB

I use USB in VCP, work very well.

ANd I enable ADC in PA0

The adc work very well, but when inizialize USB primarily the

USB_Cable_Config(ENABLE); , enable the USB internal pull-up .

This

instruction

stops the operation

of ADC.

Why? , post the code

1 REPLY 1
michelemancini2
Associate III
Posted on June 21, 2014 at 11:04

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
ADC_Cmd(ADC1, DISABLE); 
NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_24Cycles);
ADC_Cmd(ADC1, ENABLE); 
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)
{
}
ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
// Test ADC , if work
ADC_SoftwareStartConv(ADC1);
DelayMs(1000); //Work, adc go in interrupt at finish conversion (ADC1_IRQHandler)
//Now , enable USB!
// **********************************ENABLE USB *********************************
// see officila library ''STM32_USB-FS-Device_Lib_V4.0.0'' , example ''VirtualComport_Loopback''
Set_System();
Set_USBClock();
USB_Interrupts_Config();
USB_Init();

while(1){
ADC_SoftwareStartConv(ADC1); // ***> NOT Work!!!!! <***** , adc never go in interrupt !!!!
DelayMs(1000);
}