AnsweredAssumed Answered

STM32F373 SDADC2,3 problem

Question asked by dindang.settavut on Oct 6, 2014
Latest reply on Nov 25, 2015 by dindang.settavut
Hello community.

This first question. I currently try to used SDADC1,2 and 3 in STM32F373VBT6. This hardware SDADC1 and SDADC 2 used ch.0 and SDADC3 used ch.8
SDADC configurati
  • [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/NewForm.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32&ContentTypeId=0x01200200770978C69A1141439FE559EB459D758000AEE4C5D5F6F7794783CEF933B9BACC13&Source=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx#] 
  • on as
    - Single-end zero reference mode
    - Continuous conversion
    - Gain = 1
    - Internal Vref (1.8V)

    SDADC1 work fine and conversion value is correct, but SDADC2 and SDADC3 return 32767 always. I tried change mode to diff and single end offset but no something happened. Initialize function of SDADC2,3 also copy from SDADC1. I tried to check many time.
    Check pin connect is correct ?  No any pin short to GND or VCC or short together I 'm sure.
    Clock is supply, ADON bit is set because conversion complete flag is set.
    Tried to enable only single SDADC2 or SDADC3 while testing.
    GPIO pin initialize correct at analog mode and clock is supplied.

    Can anyone suggest me. Thanks and regards :)

    static void ppInitSDADC1(void)
    {
        SDADC_InitTypeDef SDADC_InitStructure;
        SDADC_AINStructTypeDef SDADC_AINStructure;
     
        // 1. Wakeup SDADC1 from power down mode.
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
        PWR_SDADCAnalogCmd(PWR_SDADCAnalog_1, ENABLE);
        // After wake-up wait a minute for stabilize process.
        while(SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_STABIP) == SET);
     
        // 1.1 Force SDADC is disable state
        SDADC_DeInit(SDADC1);
        SDADC_Cmd(SDADC1, DISABLE);
        while(SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_STABIP) == SET);
        SysTick_Sleep(100);
     
        // 2. Set clock = 72 MHz/12 = 6MHz
        RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div12);
     
        // 3. Enable peripheral clock.
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC1, ENABLE);
        SysTick_Sleep(100);
     
        // 4.1 Configure VREF as 1.8V Internal
        SDADC_VREFSelect(SDADC_VREF_VREFINT2);
        SysTick_Sleep(100); // 10 millisecond delay
     
        // 4.2 Force no power down or standby mode. Always ON
        SDADC_PowerDownCmd(SDADC1,DISABLE);
        SDADC_StandbyCmd(SDADC1,DISABLE);
     
        // 5. Enable peripheral now.
        SDADC_Cmd(SDADC1, ENABLE);
        while(SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_STABIP) == SET);
     
        // 6. Enter to initialize mode.
        SDADC_InitModeCmd(SDADC1, ENABLE);
        while(SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_INITRDY) == RESET);
     
        // 7. Configure the analog inputs. Used single end zero reference mode.
        SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEZeroReference ;
        SDADC_AINStructure.SDADC_Gain = SDADC_Gain_1;
        SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA; // Select SDADC VSSA as common mode
        SDADC_AINStructure.SDADC_Offset = (uint32_t)(0x00000000); // Ignore.
        SDADC_AINInit(SDADC1, SDADC_Conf_0, &SDADC_AINStructure);
     
        // 8. Associate configuration to channel
        SDADC_ChannelConfig(SDADC1, SDADC_Channel_0, SDADC_Conf_0);
     
        // 9. Select regular channel and conversion mode.
        SDADC_InitStructure.SDADC_Channel = SDADC_Channel_0;
        SDADC_InitStructure.SDADC_ContinuousConvMode = ENABLE;
        SDADC_InitStructure.SDADC_FastConversionMode = DISABLE;
        SDADC_Init(SDADC1, &SDADC_InitStructure);
     
        // Configure calibration process
        SDADC_CalibrationSequenceConfig(SDADC1, SDADC_CalibrationSequence_3);
     
    //  trace_printf("In INIT mode\r\n");
    //  trace_printf("SDADC1->CR1 = 0x%X\r\n",SDADC1->CR1);
    //  trace_printf("SDADC1->CR2 = 0x%X\r\n",SDADC1->CR2);
    //  trace_printf("SDADC1->ISR = 0x%X\r\n",SDADC1->ISR);
    //  assert_param((SDADC1->CR2 & 0x01) == 0x01); // ADON
    //  assert_param((SDADC1->ISR & 0x80000000) == 0x80000000); // INIT
    //  assert_param((SDADC1->ISR & (1 << 14)) != (1 << 14)); //RCIP
    //  assert_param((SDADC1->CR1 & 0x80000000) != 0x80000000); // INIT
     
        // 11. Exit from initialize mode.
        SDADC_InitModeCmd(SDADC1, DISABLE);
        while(SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_INITRDY) == SET);
     
        // Start calibration process first.
        SDADC_StartCalibration(SDADC1);
        while(SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_EOCAL) == RESET);
     
        // Then trigger software conversion
        SDADC_SoftwareStartConv(SDADC1);
        //assert_param((SDADC1->CR2 & (1 << 22)) == (1 << 22)); // RCONT
     
    //  trace_printf("Out of INIT mode\r\n");
    //  trace_printf("SDADC1->CR1 = 0x%X\r\n",SDADC1->CR1);
    //  trace_printf("SDADC1->CR2 = 0x%X\r\n",SDADC1->CR2);
    //  trace_printf("SDADC1->ISR = 0x%X\r\n",SDADC1->ISR);
        // Validate initialize
        assert_param((SDADC1->CR1 & (1 << 31)) == 0); // INIT init mode is disable
        assert_param((SDADC1->CR1 & (1 << 12)) == 0); // PDI do not enter to power down mode
        assert_param((SDADC1->CR1 & (1 << 11)) == 0); // SBI do not enter to stand mode
        //assert_param((SDADC1->CR1 & (1 << 10)) == 1); // SLOWCK slow clock enable
        //assert_param((SDADC1->CR2 & 0x01) == 1); // ADON
     
        SysTick_Sleep(100);
    }
     
    /**
     *
     */
    static void ppInitSDADC2(void)
    {
        SDADC_InitTypeDef SDADC_InitStructure;
        SDADC_AINStructTypeDef SDADC_AINStructure;
     
        // 1. Wake-up SDADC from power down mode.
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
        PWR_SDADCAnalogCmd(PWR_SDADCAnalog_2, ENABLE);
     
        // After wake-up wait a minute for stabilize process.
        while(SDADC_GetFlagStatus(SDADC2, SDADC_FLAG_STABIP) == SET);
     
        // 1.1 Force SDADC is disable state.
        SDADC_DeInit(SDADC2);
        SDADC_Cmd(SDADC2, DISABLE);
        while(SDADC_GetFlagStatus(SDADC2, SDADC_FLAG_STABIP) == SET);
        SysTick_Sleep(100);
     
        // 2. Set clock = 72 MHz/12 = 6MHz
        RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div12);
     
        // 3. Enable peripheral clock.
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC2, ENABLE);
        SysTick_Sleep(100);
     
        // 4.1 Configure VREF as 1.2V Internal
        SDADC_VREFSelect(SDADC_VREF_VREFINT1);
        SysTick_Sleep(100);
     
        // 4.2 Force no power down or standby mode. Always ON
        SDADC_PowerDownCmd(SDADC2, DISABLE);
        SDADC_StandbyCmd(SDADC2, DISABLE);
     
        // 5. Enable peripheral now.
        SDADC_Cmd(SDADC2, ENABLE);
        while(SDADC_GetFlagStatus(SDADC2, SDADC_FLAG_STABIP) == SET);
     
        // 6. Enter to initialize mode.
        SDADC_InitModeCmd(SDADC2, ENABLE);
        while(SDADC_GetFlagStatus(SDADC2, SDADC_FLAG_INITRDY) == RESET);
     
        // 7. Configure the analog inputs. Used single-end mode with zero offset. No amplified.
        SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEZeroReference ;
        SDADC_AINStructure.SDADC_Gain = SDADC_Gain_1;
        SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA; // Select SDADC VSSA as common mode
        SDADC_AINStructure.SDADC_Offset = (uint32_t)(0x00000000); // Ignore.
        SDADC_AINInit(SDADC2, SDADC_Conf_1, &SDADC_AINStructure);
     
        // 8. Associate configuration to channel
        SDADC_ChannelConfig(SDADC2, SDADC_Channel_0, SDADC_Conf_1);
     
        // 9. Select regular channel and conversion mode.
        SDADC_InitStructure.SDADC_Channel = SDADC_Channel_0;
        SDADC_InitStructure.SDADC_ContinuousConvMode = ENABLE;
        SDADC_InitStructure.SDADC_FastConversionMode = DISABLE;
        SDADC_Init(SDADC2, &SDADC_InitStructure);
     
        // 10. Configure calibration process
        SDADC_CalibrationSequenceConfig(SDADC2, SDADC_CalibrationSequence_3);
     
        // 11. Exit from initialize mode.
        SDADC_InitModeCmd(SDADC2, DISABLE);
        while(SDADC_GetFlagStatus(SDADC2, SDADC_FLAG_INITRDY) == SET);
     
        // 12. Start calibration process first.
        SDADC_StartCalibration(SDADC2);
        while(SDADC_GetFlagStatus(SDADC2, SDADC_FLAG_EOCAL) == RESET);
     
        // 13. Then activate software conversion
        SDADC_SoftwareStartConv(SDADC2);
        SysTick_Sleep(100);
    }
     
    /**
     *
     */
    static void ppInitSDADC3(void)
    {
        SDADC_InitTypeDef SDADC_InitStructure;
        SDADC_AINStructTypeDef SDADC_AINStructure;
     
        // 1. Wake-up SDADC from power down mode.
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
        PWR_SDADCAnalogCmd(PWR_SDADCAnalog_3, ENABLE);
     
        // After wake-up wait a minute for stabilize process.
        while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_STABIP) == SET);
     
        // 1.1 Force SDADC is disable state.
        SDADC_DeInit(SDADC3);
        SDADC_Cmd(SDADC3, DISABLE);
        while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_STABIP) == SET);
        SysTick_Sleep(100);
     
        // 2. Set clock = 72 MHz/12 = 6MHz
        RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div12);
     
        // 3. Enable peripheral clock.
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC3, ENABLE);
        SysTick_Sleep(100);
     
        // 4.1 Configure VREF as 1.8V Internal
        SDADC_VREFSelect(SDADC_VREF_VREFINT2);
        SysTick_Sleep(100);
     
        // 4.2 Force no power down or standby mode. Always ON
        SDADC_PowerDownCmd(SDADC3, DISABLE);
        SDADC_StandbyCmd(SDADC3, DISABLE);
     
        // 5. Enable peripheral now.
        SDADC_Cmd(SDADC3, ENABLE);
        while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_STABIP) == SET);
     
        // 6. Enter to initialize mode.
        SDADC_InitModeCmd(SDADC3, ENABLE);
        while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_INITRDY) == RESET);
     
        // 7. Configure the analog inputs. Used single-end mode with zero offset. No amplified.
        SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEOffset;
        SDADC_AINStructure.SDADC_Gain = SDADC_Gain_1;
        SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA; // Select SDADC VSSA as common mode
        SDADC_AINStructure.SDADC_Offset = (uint32_t)(0x00000000); // Ignore.
        SDADC_AINInit(SDADC3, SDADC_Conf_2, &SDADC_AINStructure);
     
        // 8. Associate configuration to channel
        SDADC_ChannelConfig(SDADC3, SDADC_Channel_8, SDADC_Conf_2);
     
        // 9. Select regular channel and conversion mode.
        SDADC_InitStructure.SDADC_Channel = SDADC_Channel_8;
        SDADC_InitStructure.SDADC_ContinuousConvMode = ENABLE;
        SDADC_InitStructure.SDADC_FastConversionMode = DISABLE;
        SDADC_Init(SDADC3, &SDADC_InitStructure);
     
        // 10. Configure calibration process
        SDADC_CalibrationSequenceConfig(SDADC3, SDADC_CalibrationSequence_3);
     
        // 11. Exit from initialize mode.
        SDADC_InitModeCmd(SDADC3, DISABLE);
        while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_INITRDY) == SET);
     
        // 12. Start calibration process first.
        SDADC_StartCalibration(SDADC3);
        while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_EOCAL) == RESET);
     
        // 13. Then activate software conversion
        SDADC_SoftwareStartConv(SDADC3);
        SysTick_Sleep(100);
    }









    Outcomes