Hallo, ich arbeite mit einem STM32F103RBT6 und möchte 6 Analogeingänge einlesen. Problem 1 lässt sich wie folgt beschreiben: PC.2 lässt sich nicht einlesen. Wert = 0 obwohl ein Signal am PIN laut Oszi. anliegt. Hab ich evtl. irgendwo einen Copy+Paste Fehler eingebaut? Problem 2: PC5 liefert einen irritierenden Wert. Dieser erscheint ohne und mit anliegendem Signal eim Eingang! Bei Auskommentieren des ADC-Textes verschiebt sich dieser irritierende Wert auf PC4!! Vorher hatten PC3 und PC4 den Wert 0 oder den des anliegenden Signals (Wieder mit dem Oszi nachgemessen). Scheint mir dann doch in die Richtung eines Softwareproblems zu gehen. Problem 3: PC0-1 liefern ohne anliegendes Signal viel zu hohe Werte. Bei anliegendem Signal arbeitet der ADC aber korrekt. ----------- Könnte jemand mal über den Code gucken? Vermute doch starkt das es ein Softwareproblem ist da 4 von 6 Eingängen ja korrekt eingelesen werden bei anliegendem Signal! Hoffe es ist alles vorhanden und ich habe keinen Code vergessen. Schöne Grüße, Christopher! --------------------------------------------------------------- void ADC_Configuration(void) { ADC_InitTypeDef ADC_InitStructure; /* 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 = 1; ADC_Init(ADC1, &ADC_InitStructure); /* 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)); } ------------------------------------------------------------------ /* Configure PC.0, PC.1, PC.2 (ADC Channel10..12, as analog inputs */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure PC.3, PC.4, PC.5 (ADC Channel10..12, as analog inputs */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &GPIO_InitStructure); ------------------------------------------------------------------ void GetAD_values(void) { //ADC1 ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_55Cycles5); //PIN PC0 ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); voltage0=ADC_GetConversionValue(ADC1); Delay(5); ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_55Cycles5); //PIN PC1 ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); voltage1=ADC_GetConversionValue(ADC1); Delay(5); ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_55Cycles5); //PIN PC2 ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); voltage2=ADC_GetConversionValue(ADC1); Delay(5); ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 1, ADC_SampleTime_55Cycles5); //PIN PC3 ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); voltage3=ADC_GetConversionValue(ADC1); Delay(5); ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5); //PIN PC4 ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); voltage4=ADC_GetConversionValue(ADC1); Delay(5); ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_55Cycles5); //PIN PC5 ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); voltage5=ADC_GetConversionValue(ADC1); Delay(5); }
Clocks gestartet ? For single conversion mode (DMA is nicht benotigt): /* ADC1 configuration for single conversion--------------------------------*/ ADC_InitTypeDef ADC_InitStructure; // Put everything back to power-on defaults /* ADC_DeInit(ADC1); // ADC1 Configuration ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // ADC1 and ADC2 operate independantly ADC_InitStructure.ADC_ScanConvMode = DISABLE; // Disable the scan conversion so we do one at a time ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //Don't do contimuous conversions - do them on demand ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; // Start conversin by software, not an external trigger ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; // Conversions are 12 bit - put them in the lower 12 bits of the result ADC_InitStructure.ADC_NbrOfChannel = 1; // Say how many channels would be used by the sequencer ADC_Init(ADC1,&ADC_InitStructure); // Now do the setup */
hier der Code: /* Enable ADC1, ADC2, ADC3 and GPIOC clocks */ RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_ADC3, ENABLE); RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE); RCC_APB1PeriphClockCmd( SPI_MASTER_GPIO_CLK | RCC_APB1Periph_SPI2, ENABLE);
Hi, habe hier nochmal eben die init.c hochgeladen. Falls nötig kann ich noch die Main.c hochladen. Alles wichtige daraus sollte aber im ersten Post stehen. Seltsam halt, dass er 4 einliest (auch wenn mit problemen), aber die anderen beiden absolut nicht reagieren. Schöne Grüße
Ich habe den Fehler gefunden. Nachdem ich die Abfragen der ADC-Werte in zwei Funktionen aufgeteilt habe und diese zu unterschiedlichen Zeitpunkten aufgerufen habe gings problemlos! MfG, Chris
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
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.