stm32f0, adc, basic single conversion, multiple channel - problem

tomas mainzer t.mainzer na gmail.com
Čtvrtek Prosinec 8 09:15:17 CET 2016


DD,
dekuji ze jste me na to se donutil podivat:-)
hodnota je vicemene spravna ;-)  ADC_Channel_2, ADC_Channel_3 atp....  ALE:
knihovni fce ADC_ChannelConfig() dela s tim registrem OR a nikde jej
nenuluje, takze vy vysledku jsou tam v mem pripade nastaveny 4 bity. Nevite
nekdo proc?
(kdyz tam dam proste prirazeni, tak (se zda) vse funguje jak ma)

Zde ta fce:

void ADC_ChannelConfig(ADC_TypeDef* ADCx, uint32_t ADC_Channel, uint32_t
ADC_SampleTime)
{
  uint32_t tmpreg = 0;

  /* Check the parameters */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));
  assert_param(IS_ADC_CHANNEL(ADC_Channel));
  assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));

  /* Configure the ADC Channel */
  ADCx->CHSELR |= (uint32_t)ADC_Channel;  //this seems to be inccorrect for
multiple channel single conversion reading
//ADCx->CHSELR = (uint32_t)ADC_Channel;   //this seems to be correct (!?)

  /* Clear the Sampling time Selection bits */
  tmpreg &= ~ADC_SMPR1_SMPR;

  /* Set the ADC Sampling Time register */
  tmpreg |= (uint32_t)ADC_SampleTime;

  /* Configure the ADC Sample time register */
  ADCx->SMPR = tmpreg ;
}


2016-12-08 7:48 GMT+01:00 Jan Waclawek <konfera na efton.sk>:

> Aka je hodnota ADC_CHSELR?
>
> wek
>
> ----- Original Message ---------------
> >DD,
> >mam potize ze zprovoznenim ADC na STM32f042. Postupne ctu 4 vstupy
> >(2*Externi vstup, 2*Interni). Zrejme je nejaka potiz v casovani nebo
> >kontroluji spatne bity pro konec konverze(?) nebot pri cteni kanaly
> >vzajemne obcas "preskakuji" (tj. co mam na jednom vstupu ctu najednou na
> >jinem).
> >Nize prikladam kod, jestli by si nekdo nevsiml kde je chyba.
> >(pozn: vsechny priklady pro single conversion od ST (pro std lib) ctou
> >opakovane jen jeden vstup)
> >Dekuji, T.M.
> >
> >//*** ADC initialisaion ****************
> >static void ADC_Config(void)
> >{
> >  ADC_InitTypeDef     ADC_InitStructure;
> >  GPIO_InitTypeDef    GPIO_InitStructure;
> >
> >  /* GPIOC Periph clock enable */
> >  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
> >
> >  /* ADC1 Periph clock enable */
> >  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
> >
> >  /* Configure ADC Channels as analog input */
> >  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
> >  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
> >  GPIO_InitStructure.GPIO_Pin = SIGN_EA;  //PA3, GPIO_Pin_3, ADC_Channel_3
> >  GPIO_Init(SIGP_EA, &GPIO_InitStructure);
> >  /* Configure ADC Channels as analog input */
> >  GPIO_InitStructure.GPIO_Pin = SIGN_EB;  //PA2, GPIO_Pin_2, ADC_Channel_2
> >  GPIO_Init(SIGP_EB, &GPIO_InitStructure);
> >  /* Configure ADC Channels as analog input */
> >  GPIO_InitStructure.GPIO_Pin = SIGN_AI0;  //PB0, Nastavo jako AI, neni
> >cteno
> >  GPIO_Init(SIGP_AI0, &GPIO_InitStructure);
> >  /* Configure ADC Channels as analog input */
> >  GPIO_InitStructure.GPIO_Pin = SIGN_AI1;  //PB1, Nastavo jako AI, neni
> >cteno
> >  GPIO_Init(SIGP_AI1, &GPIO_InitStructure);
> >
> >  /* ADCs DeInit */
> >  ADC_DeInit(ADC1);
> >
> >  /* Initialize ADC structure */
> >  ADC_StructInit(&ADC_InitStructure);
> >  ADC_ClockModeConfig(ADC1,ADC_ClockMode_AsynClk);
> >  ADC_AutoPowerOffCmd(ADC1,DISABLE);
> >  /* Configure the ADC1 in continuous mode with a resolution equal to 12
> >bits  */
> >  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_ScanDirection = ADC_ScanDirection_Upward;
> >  ADC_Init(ADC1, &ADC_InitStructure);
> >
> >  /* ADC Calibration */
> >  ADC_GetCalibrationFactor(ADC1);
> >
> >  /* Enable the ADC peripheral */
> >  ADC_Cmd(ADC1, ENABLE);
> >
> >  /* Wait the ADRDY flag */
> >  while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
> >
> >
> >  /* Enable VREF_INT & Temperature channel */
> >  ADC_ChannelConfig(ADC1, ADC_Channel_TempSensor ,
> >ADC_SampleTime_55_5Cycles);
> >  ADC_TempSensorCmd(ENABLE);
> >  ADC_ChannelConfig(ADC1, ADC_Channel_Vrefint ,
> ADC_SampleTime_55_5Cycles);
> >  ADC_VrefintCmd(ENABLE);
> >}
> >
> >//*** read ADCinput <channel>  ***********
> >uint16_t adc_read(ADC_TypeDef* ADCx, uint32_t channel, uint32_t
> >ADC_SampleTime) {
> >
> > /* Configure Channel */
> > ADC_ChannelConfig(ADCx, channel, ADC_SampleTime);
> >
> > /* check if conversion was started, if not start */
> > ADC_StartOfConversion(ADCx);
> >
> > /* wait for end of conversion */
> > while((ADC_GetFlagStatus(ADCx, ADC_FLAG_EOC) == RESET));
> >
> > return ADC_GetConversionValue(ADCx);
> >
> >}
> >
> >
> >#define ADCSAMPLETIME ADC_SampleTime_28_5Cycles
> >
> >//****** ....main loop:  ****************************
> >....
> >a = adc_read(ADC1, ADC_Channel_17, ADCSAMPLETIME); //vref voltage
> >b = adc_read(ADC1,ADC_Channel_16,ADCSAMPLETIME); //internal temperature
> >c = adc_read(ADC1,SIGA_EB,ADCSAMPLETIME); //analog in, ADC_Channel_2
> >d = adc_read(ADC1,SIGA_EA,ADCSAMPLETIME); //analog in, ADC_Channel_3
> >.....
>
> _______________________________________________
> HW-list mailing list  -  sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
>
------------- další část ---------------
HTML příloha byla odstraněna...
URL: <http://list.hw.cz/pipermail/hw-list/attachments/20161208/0e966a4b/attachment-0001.html>


Další informace o konferenci Hw-list