2015-10-26 05:55 AM
Hi,
I hope someone can help me. We do have some strange behaviour with our STM32F4-Discovery Boards. Currently we capture analog data on two channels. Both channels are configured equally. Despite equal configuration the ADC channels behave differently, when connecting the same signal source and measuring the input voltage. On channel 2 the voltage drops to 0.5V. This is lower bound of the preceding amplifier. When measuring on channel 0 and connecting the oscilloscope the voltage stays the same. Can someone example this strange behaviour?/* ADC3 init function */
void MX_ADC3_Init(void) { ADC_ChannelConfTypeDef sConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc3.Instance = ADC3; hadc3.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV8; hadc3.Init.Resolution = ADC_RESOLUTION12b; hadc3.Init.ScanConvMode = ENABLE; hadc3.Init.ContinuousConvMode = ENABLE; hadc3.Init.DiscontinuousConvMode = DISABLE; hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc3.Init.NbrOfConversion = 2; hadc3.Init.DMAContinuousRequests = ENABLE; hadc3.Init.EOCSelection = EOC_SINGLE_CONV; HAL_ADC_Init(&hadc3); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_0; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_144CYCLES; HAL_ADC_ConfigChannel(&hadc3, &sConfig); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_2; sConfig.Rank = 2; HAL_ADC_ConfigChannel(&hadc3, &sConfig); }2015-10-26 06:03 AM
We have tested this on different boards and with different signal sources. The behaviour stays the same.
And this is the missing configuration and start code. configuration code:else if(hadc->Instance==ADC3)
{ /* USER CODE BEGIN ADC3_MspInit 0 */ /* USER CODE END ADC3_MspInit 0 */ /* Peripheral clock enable */ __ADC3_CLK_ENABLE(); /**ADC3 GPIO Configuration PA0/WKUP ------> ADC3_IN0 PA2 ------> ADC3_IN2 */ GPIO_InitStruct.Pin = SIGNAL_IN_I_Pin|SIGNAL_IN_Q_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc3.Instance = DMA2_Stream1; hdma_adc3.Init.Channel = DMA_CHANNEL_2; hdma_adc3.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc3.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc3.Init.MemInc = DMA_MINC_ENABLE; hdma_adc3.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; hdma_adc3.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_adc3.Init.Mode = DMA_CIRCULAR; hdma_adc3.Init.Priority = DMA_PRIORITY_LOW; hdma_adc3.Init.FIFOMode = DMA_FIFOMODE_ENABLE; hdma_adc3.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; hdma_adc3.Init.MemBurst = DMA_MBURST_SINGLE; hdma_adc3.Init.PeriphBurst = DMA_PBURST_SINGLE; HAL_DMA_Init(&hdma_adc3); __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc3); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(ADC_IRQn, 0, 0); HAL_NVIC_EnableIRQ(ADC_IRQn); /* USER CODE BEGIN ADC3_MspInit 1 */ /* USER CODE END ADC3_MspInit 1 */ } start code:void startInputADC(uint32_t* memory, uint32_t size) {
if(HAL_ADC_Start(&hadc3) != HAL_OK) { printf(''error starting ADC3''); } if (HAL_ADC_Start_DMA(&hadc3, memory, size) != HAL_OK) { printf(''error starting DMA for ADC3''); } if (HAL_ADC_Start_IT(&hadc3) != HAL_OK) { printf(''error starting interrupts for ADC3''); } }2015-10-26 06:03 AM
You think it might be salient to specify which pins exactly are being used here?
2015-10-26 06:17 AM
PA0 is connected to the User button circuitry.
Do other pins work if connected to VCC and GND respectively? ie read as 0xFFF and 0x000, approximately2015-10-27 03:54 AM
Okay, so that's why PA0 behaves differently. Unfortunately in STM32CubeMX PA0 is selected automatically for Channel 0 and there is no way to change it within the application.
Also PA0 behaves as expected and channel 2 on PA2 behaves strange.