2014-01-09 05:22 AM
Hello Everybody,
i'm trying to modify joystick demo from STM32_USB-FS-Device_Lib_V3.4.0I want to control movement by thumb joystick. However, when i initialize ADC (or usart) it won't jump to interrupt routine. At the same the, the debugger is not working.I have found out that debugger and interrupts start wroking when i comment out: _SetCNTR(wInterrupt_Mask); line 57 in usb_sil.c ( setting wInterrupt_Mask = IMR_MSK; ) _SetCNTR(wInterrupt_Mask); line 80 in usb_pwr.c ( setting wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM; )Any idea what might be the problem ? #stm32l-discovery-usb-mouse2014-01-10 06:50 AM
Hi
The 2 files you mention do not ring a bell (I do not remember coming across them). If they are in : \Libraries\STM32_USB_Device_Library \Libraries\STM32_USB_HOST_Library \Libraries\STM32_USB_OTG_Library \Libraries\STM32F-----_StdPeriph_Driver then you are best to leave them alone. They should work without any modifications! The files that you should look at for your application are in \Project\HID because you are looking at the Human Interface Device example.2014-01-13 06:02 AM
Hello
thanks for reply. Yes i know. I'm not touching USB stuff. I was just curious what is causing the malfunction. Originally i'm playing in main().2014-01-13 06:08 AM
Hi
''I was just curious what is causing the malfunction.'' The USB OTG (and the other one, HS I think ) are heavily IRQ drivern. The code you showed was enabling IRQs - if you do not enable them - it will cripple the whole USB driver.2014-01-13 06:39 AM
Yes i know ...
But i was trying to also enable ADC inerrupt but it was not working. It started to work after disabling those 2 lines. This is my ADC Init routine: void Initialize_ADC(void) { uint32_t Timeout = 1000000; ADC_InitTypeDef ADC_InitStruct; GPIO_InitTypeDef GPIO_InitStructure; /* Set GPIOB8 to Analog mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Set GPIOB9 to Analog mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Enable ADC clock & SYSCFG */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* Enable HSI for ADC */ RCC_HSICmd(ENABLE); while((RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET) && (Timeout != 0)) { Timeout--; } ADC_InitStruct.ADC_Resolution = ADC_Resolution_8b; // ADC_InitStruct.ADC_ScanConvMode = ENABLE; ADC_InitStruct.ADC_ScanConvMode = DISABLE; ADC_InitStruct.ADC_ContinuousConvMode = DISABLE; ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; //ADC_InitStruct.ADC_ExternalTrigConv; ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right ; // ADC_InitStruct.ADC_NbrOfConversion = 2; ADC_InitStruct.ADC_NbrOfConversion = 1; /* Initialize ADC Periperal */ ADC_Init(ADC1, &ADC_InitStruct); /* Delay applied after conversion or a sequence of conversions */ ADC_DelaySelectionConfig(ADC1,ADC_DelayLength_Freeze); //ADC_PowerDownCmd(ADC1,ADC_PowerDown_Idle_Delay, DISABLE); /* Enables or disables the EOC on each regular channel conversion. */ ADC_EOCOnEachRegularChannelCmd(ADC1, ENABLE); /* Configure Regular channel, Channel 0 and 1, Rank 1 and 2, 96 sample cycles PB8 PB9*/ // ADC_RegularChannelConfig(ADC1, (uint8_t) ADC_Channel_23,(uint8_t) 23, (uint8_t) ADC_SampleTime_384Cycles ); // ADC_RegularChannelConfig(ADC1, (uint8_t) ADC_Channel_24,(uint8_t) 24, (uint8_t) ADC_SampleTime_384Cycles ); ADC1->SMPR1 = 0x00007E00; /* 384 cycles */ ADC1->SQR1 = 0x00000000; /* number of conversion == 1 */ ADC1->SQR5 = 0x00000017; /* Enable ADC Peripheral */ ADC_Cmd(ADC1,ENABLE); }2014-01-13 06:48 AM
Hi
Where is the code to set up the ADC IRQ?2014-01-13 07:52 AM
I have it in adc.c file. All the irq does is blinking the led, just to see, if programm goes into irq.
void ADC1_IRQHandler(void) { FlipGreenLed(); (void) ADC1->DR; }2014-01-13 08:07 AM
Hi
So to summarize : The USB HID connects and enumerates. ADC does not work with IRQs Does the green LED flip?2014-01-13 12:18 PM
Yes you're right.
LED does not flip. It is in high ... it is lighted but not flipping Maybe there is some wrong setting somewhere but i don't see where :(2014-01-14 03:10 AM
Hi
''Maybe there is some wrong setting somewhere but i don't see where :('' ''Where is the code to set up the ADC IRQ?'' ''I have it in adc.c file. All the irq does is blinking the led, just to see, if programm goes into irq. void ADC1_IRQHandler(void) { FlipGreenLed(); (void) ADC1->DR; }'' No - that is the Interrupt Service Routine (ISR) code. I asked where is the code that sets up the IRQ. Hint, it will program the NVIC If you do not set up the IRQs in the NVIC - the ISRs will not be called. That is why you LED is not flipping.