stm8l DMA 2路ADC

2019-07-19 20:53发布

在做两路ADC的时候用DMA来取值,会出现这有时候两路对应寄存器的值对,有时候对应的值不对,不对的时候交换了,取值是在DMA中断里取的,下面是配置:
void DMAInit(void)
{
  /* Enable DMA1 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
  /* Connect ADC to DMA channel 0 */
  SYSCFG_REMAPDMAChannelConfig(REMAP_DMA1Channel_ADC1ToChannel0);
  DMA_GlobalDeInit();
  DMA_DeInit(DMA1_Channel0);
  
  DMA_Init(DMA1_Channel0, BUFFER_ADDRESS,
           ADC1_DR_ADDRESS,
           BUFFER_SIZE,
           DMA_DIR_PeripheralToMemory,
           DMA_Mode_Circular,
           DMA_MemoryIncMode_Inc,
           DMA_Priority_High,
           DMA_MemoryDataSize_HalfWord);

  /* DMA Channel0 enable */
  DMA_Cmd(DMA1_Channel0, ENABLE);

  /* Enable DMA1 channel0 Transfer complete interrupt */
  DMA_ITConfig(DMA1_Channel0, DMA_ITx_TC, ENABLE);
  
  /* DMA enable */
  DMA_GlobalCmd(ENABLE);
  
}

void ADCInit(void)
{
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
   // de-initialize ADC
  ADC_DeInit(ADC1);

  // ADC configuration ---------------------------------------//
  ADC_Init(ADC1, ADC_ConversionMode_Continuous,
           ADC_Resolution_12Bit, ADC_Prescaler_1);
   // SampleTime: 384 cycles
  ADC_SamplingTimeConfig(ADC1,ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
  
  ADC_ChannelCmd(ADC1,ADC_Channel_16,ENABLE);
  ADC_ChannelCmd(ADC1,ADC_Channel_17,ENABLE);
  ADC_DMACmd(ADC1,ENABLE);
  
  ADC_VrefintCmd(ENABLE);
  // enable ADC
  ADC_Cmd(ADC1,ENABLE);
  ADC_SoftwareStartConv(ADC1);
  // start ADC convertion by software
  //ADC1->CR1 |= ADC_CR1_START;
  // wait until end-of-covertion
  //while( ADC_GetFlagStatus(ADC_FLAG_EOC) == 0 ) ;
//value = ADC_GetConversionValue();

}

是我配置不对还是取值不对?

INTERRUPT_HANDLER(DMA1_CHANNEL0_1_IRQHandler,2)
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */  
  
    /* Calculate RV2 voltage value*/
  RV16Voltage = (uint32_t)((uint32_t)Buffer[0] * (uint32_t)ADC_RATIO) / 1000;


  /* Calculate CN15 voltage value*/
  CN17Voltage = (uint32_t)((uint32_t)Buffer[1] * (uint32_t)ADC_RATIO) / 1000;
  /* Clear IT Pending Bit */
  DMA_ClearITPendingBit(DMA1_IT_TC0);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。