0

I am facing the issue that ADC DMA cannot work even I try re-init in many ways. Information:

  • STM32L476

  • Stop mode and wake up via RTC

  • Can re-init USB so the terminal still works

  • Clock configuration clock configuration

  • Only STOP mode has this issue. SLEEP mode ADC DMA triggers and works properly

  • STM32 goes to stop mode and wake up properly.

  • Print result register after wake up ADC ISR=0x00000003, CR=0x10000005, CFGR=0x80001903 TIM3 CR1=0x0001, CNT=6606, SR=0x001f

  • ADC conversion call by TIM3 event interrupt, enable DMA request continous.

  • I read ADCbuffer again and again but it does not update, no ADC & DMA interrupt

Can you help me to fix this problem? Here is my code:

uint32_t ADCbuffer[14];  // DMA/ADC result buffer
static uint32_t tick = 0;
int main(void)
{
    /* USER CODE BEGIN 1 */

    /* USER CODE END 1 */

    /* MCU Configuration--------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* USER CODE BEGIN Init */

    /* USER CODE END Init */

    /* Configure the system clock */
    SystemClock_Config();

    /* Configure the peripherals common clocks */
    PeriphCommonClock_Config();

    /* USER CODE BEGIN SysInit */

    /* USER CODE END SysInit */

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_ADC1_Init();
    MX_USART1_UART_Init();
    MX_TIM3_Init();
    MX_USB_DEVICE_Init();
    MX_RTC_Init();
    MX_TIM2_Init();
    MX_ADC2_Init();
    /* USER CODE BEGIN 2 */

    //BEEEEPPP
    HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
    htim2.Instance->CCR2 = htim2.Instance->ARR/2;
    HAL_Delay(200);
    htim2.Instance->CCR2 = 0;


    //Start the ADC and triggers
    //ADC1 regular conversions are triggered by timer3 which also gates the dividers
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
    htim3.Instance->CCR1 = htim3.Instance->ARR;
    htim3.Instance->CCR4 = 2000;

    GPIOB->ASCR |=0x01;

    HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
    HAL_Delay(200);


    HAL_ADC_Start_DMA(&hadc1, ADCbuffer,14);
    __HAL_ADC_ENABLE_IT(&hadc1, ADC_IT_EOS);
    HAL_ADCEx_InjectedStart(&hadc2);

    uint8_t HiMsg[] = "hello\r\n";
    CDC_Transmit_FS(HiMsg, strlen(HiMsg));
    //Now we have a short delay to allow some initial readings to come in from the ADC
    HAL_Delay(500);

    /* USER CODE END 2 */

    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1)
    {
        if (HAL_GetTick() - tick > 30000)
        {
            tick = HAL_GetTick();
            HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 0); //LED OFF
            HAL_SuspendTick();
            HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 20480, RTC_WAKEUPCLOCK_RTCCLK_DIV16); //32768/16 = 2048
            __disable_irq();
            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
            __enable_irq();
            HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
            SystemClock_Config();
            HAL_ResumeTick();
            HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 1); //LED ON
            // init ADC hereeee
            // ...
            MX_USB_DEVICE_Init();
            //Bip
            HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
            htim2.Instance->CCR2 = htim2.Instance->ARR/2;
            HAL_Delay(2);
            htim2.Instance->CCR2 = 0;
            HAL_Delay(2000);
            uint8_t HiMsg[] = "hello\r\n";
            CDC_Transmit_FS(HiMsg, strlen(HiMsg));
            HAL_Delay(50);
            HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_2);
        }
        /* USER CODE END WHILE */

        /* USER CODE BEGIN 3 */
    }
    /* USER CODE END 3 */
}
1
  • I found the problem, I forgot init peripheral clock, my bad Commented Nov 5 at 8:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.