Ignore:
Timestamp:
Aug 29, 2025, 6:15:42 PM (24 hours ago)
Author:
f.jahn
Message:

DMA Rx funktioniert, aber BETA und nur feste Baudrate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/fw_g473rct/Core/Src/adc.c

    r20 r22  
    5959  hadc1.Init.GainCompensation = 0;
    6060  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
    61   hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
     61  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    6262  hadc1.Init.LowPowerAutoWait = DISABLE;
    6363  hadc1.Init.ContinuousConvMode = ENABLE;
     
    6868  hadc1.Init.DMAContinuousRequests = ENABLE;
    6969  hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
    70   hadc1.Init.OversamplingMode = DISABLE;
     70  hadc1.Init.OversamplingMode = ENABLE;
     71  hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256;
     72  hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
     73  hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
     74  hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
    7175  if (HAL_ADC_Init(&hadc1) != HAL_OK)
    7276  {
     
    8892  sConfig.Channel = ADC_CHANNEL_1;
    8993  sConfig.Rank = ADC_REGULAR_RANK_1;
    90   sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
     94  sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
    9195  sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
    9296  sConfig.OffsetNumber = ADC_OFFSET_NONE;
     
    123127  hadc2.Init.GainCompensation = 0;
    124128  hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
    125   hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
     129  hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    126130  hadc2.Init.LowPowerAutoWait = DISABLE;
    127131  hadc2.Init.ContinuousConvMode = ENABLE;
     
    130134  hadc2.Init.DMAContinuousRequests = ENABLE;
    131135  hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
    132   hadc2.Init.OversamplingMode = DISABLE;
     136  hadc2.Init.OversamplingMode = ENABLE;
     137  hadc2.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256;
     138  hadc2.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
     139  hadc2.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
     140  hadc2.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
    133141  if (HAL_ADC_Init(&hadc2) != HAL_OK)
    134142  {
     
    140148  sConfig.Channel = ADC_CHANNEL_3;
    141149  sConfig.Rank = ADC_REGULAR_RANK_1;
    142   sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
    143   sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
     150  sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
     151  sConfig.SingleDiff = ADC_SINGLE_ENDED;
    144152  sConfig.OffsetNumber = ADC_OFFSET_NONE;
    145153  sConfig.Offset = 0;
     
    396404    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
    397405    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
    398     hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
     406    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    399407    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    400408    hdma_adc1.Init.Mode = DMA_CIRCULAR;
     
    435443    /**ADC2 GPIO Configuration
    436444    PA6     ------> ADC2_IN3
    437     PA7     ------> ADC2_IN4
    438     */
    439     GPIO_InitStruct.Pin = ADC2_IN3_UBAT__Pin|ADC2_IN4_UBAT__Pin;
     445    */
     446    GPIO_InitStruct.Pin = ADC2_IN3_UBAT__Pin;
    440447    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
    441448    GPIO_InitStruct.Pull = GPIO_NOPULL;
    442     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
     449    HAL_GPIO_Init(ADC2_IN3_UBAT__GPIO_Port, &GPIO_InitStruct);
    443450
    444451    /* ADC2 DMA Init */
     
    449456    hdma_adc2.Init.PeriphInc = DMA_PINC_DISABLE;
    450457    hdma_adc2.Init.MemInc = DMA_MINC_ENABLE;
    451     hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
     458    hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    452459    hdma_adc2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    453460    hdma_adc2.Init.Mode = DMA_CIRCULAR;
     
    665672    /**ADC2 GPIO Configuration
    666673    PA6     ------> ADC2_IN3
    667     PA7     ------> ADC2_IN4
    668     */
    669     HAL_GPIO_DeInit(GPIOA, ADC2_IN3_UBAT__Pin|ADC2_IN4_UBAT__Pin);
     674    */
     675    HAL_GPIO_DeInit(ADC2_IN3_UBAT__GPIO_Port, ADC2_IN3_UBAT__Pin);
    670676
    671677    /* ADC2 DMA DeInit */
Note: See TracChangeset for help on using the changeset viewer.