Forum: Mikrocontroller und Digitale Elektronik ARM STM32 F103ZE Problemen bei der ADC-Wandlung über DMA


von Roman H. (chumarik)


Lesenswert?

Hallo!
Ich habe ein Problem mit ADC mit Hilfe DMA Kontroller, damit ganzen 
Ablauf zugiger geht.
Ich weiß nicht wie ich mehrere Kanäle abfragen soll. Wenn ich die 
folgenden Operationen durchführe, dann habe ich nur einen falschen Wert 
in ADC1ConvertedValue[0].
Ich gehe davon aus, dass die Funktion ADC_Configuration(void) falsch 
definiert.
Hier ist mein Quellcode:

#define ADC1_DR_Address    ((uint32_t)0x4001244C)
__IO uint16_t ADC1ConvertedValue[20];

void DMA_Configuration(void)
{
  /* DMA1 channel1 configuration 
----------------------------------------------*/
    DMA_DeInit(DMA1_Channel1);
    DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
    DMA_InitStructure.DMA_MemoryBaseAddr = 
(uint32_t)&ADC1ConvertedValue;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
    DMA_InitStructure.DMA_BufferSize = 20;
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
    DMA_InitStructure.DMA_PeripheralDataSize = 
DMA_PeripheralDataSize_HalfWord;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
    DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
    DMA_Init(DMA1_Channel1, &DMA_InitStructure);
    DMA_Cmd(DMA1_Channel1, ENABLE);
}

void ADC_Configuration(void){

  /* ADC1 configuration 
------------------------------------------------------*/
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 10;
  ADC_Init(ADC1, &ADC_InitStructure);
//  /* ADC1 regular channels configuration */
  ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 3, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 4, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 5, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 6, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 7, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 8, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 9, 
ADC_SampleTime_28Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 10, 
ADC_SampleTime_28Cycles5);

  /* Enable ADC1 DMA */
  ADC_DMACmd(ADC1, ENABLE);

  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));

   /* Start ADC1 Software Conversion */
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

}

  analog.timestamp=values.timestamp;
  analog.TempSens1=ADC1ConvertedValue[0];
  analog.TempSens2=ADC1ConvertedValue[1];
  analog.Batt_Spg1=ADC1ConvertedValue[2];
  analog.Batt_Spg2=ADC1ConvertedValue[3];
  analog.Druck_Sensor=ADC1ConvertedValue[4];
  analog.Druck_Sensor_Kalt1=ADC1ConvertedValue[5];
  analog.Druck_Sensor_Kalt2=ADC1ConvertedValue[6];
  analog.Strom_Mess1=ADC1ConvertedValue[7];
  analog.Strom_Mess2=ADC1ConvertedValue[8];
  analog.Temp=ADC1ConvertedValue[9];

Die Konfiguration von GPIO und RCC sind richtig eingestellt.
Ich werde sehr dankbar, wenn jemand mir etwas schreibt. Am Ende stelle 
ich hier fuktionierende Funktionen, falls es jemand noch braucht.
MfG, Roman

von Roman H. (chumarik)


Lesenswert?

Lösung des Problems:
Ändern Initialisierung von ADC

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;        //Scan 
(multichannels - ENABLE) or Single (one channel - DISABLE) mode.
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 10;
  ADC_Init(ADC1, &ADC_InitStructure);

Und bei DMA soll Zähler bei jedem Schritt inkrementiert:
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;


Das war's.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.