cancel
Showing results for 
Search instead for 
Did you mean: 

ADC3_IN2 on STM32F427

doreen
Associate II
Posted on July 01, 2015 at 01:16

 Existing code, ADC2_IN1 on PA1 works polled 100 numbers vary from 150 to 3050 sinusoid.  HW guy added ADC3_IN2 on PA2.

Changed the code as below, but 100 numbers are all between 3013 and 3015, although can see a clipped sinusoid on Bitscope.  Any ideas what to check?

void ecg_init (void)

{

    static GPIO_InitTypeDef         GPIO_InitStructure;

    static ADC_InitTypeDef          ADC_InitStructure;

    

    // [dy] ECG_OUT2 is on PA2 ADC3_IN2

    RCC_AHB1PeriphClockCmd(BSP_ECG_ANALOG_INPUT_GPIO_RCC_AHB1_PERIPH, ENABLE);

    

    // [dy-ECG1] RCC_APB2PeriphClockCmd(BSP_ECG_ANALOG_INPUT_ADC_RCC_APB2_PERIPH, ENABLE);

    //[dy] RCC Enable for ECG2

    RCC_APB2PeriphClockCmd(BSP_ECG2_ANALOG_INPUT_ADC_RCC_APB2_PERIPH, ENABLE);

    /* Configure GPIO (ECG) as analog input ******************************/

    //[dy] GPIO_Pin_2 for ECG2

    GPIO_InitStructure.GPIO_Pin  = /* [dy-ECG1] BSP_ECG_ANALOG_INPUT_GPIO_PIN |*/ BSP_ECG2_ANALOG_INPUT_GPIO_PIN;  

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

    GPIO_Init(BSP_ECG_ANALOG_INPUT_GPIO_PORT, &GPIO_InitStructure);

    ssm_adc_common_init ();

    /* ADC ECG Init ****************************************************************/

    ADC_InitStructure.ADC_Resolution           = ADC_Resolution_12b;

    ADC_InitStructure.ADC_ScanConvMode         = DISABLE;

    ADC_InitStructure.ADC_ContinuousConvMode   = ENABLE;  // THIS WAS Different

    ADC_InitStructure.ADC_ContinuousConvMode   = DISABLE;

    ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

    ADC_InitStructure.ADC_DataAlign            = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfConversion      = 1;

    // [dy-ECG1] ADC_Init(BSP_ECG_ANALOG_INPUT_ADC_NUM, &ADC_InitStructure);

    // [dy] ADC_Init for ECG2

    ADC_Init(BSP_ECG2_ANALOG_INPUT_ADC_NUM, &ADC_InitStructure);    

    // [dy] BSP_ECG2_ANALOG_INPUT_ADC_NUM  ADC3   

    // NV 20130926 KEY Do this only once...

#ifdef ECG1    

    ADC_RegularChannelConfig(BSP_ECG_ANALOG_INPUT_ADC_NUM,

                             BSP_ECG_ANALOG_INPUT_ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);

    ADC_Cmd(BSP_ECG_ANALOG_INPUT_ADC_NUM, ENABLE);

#endif

    // [dy] BSP_ECG2_ANALOG_INPUT_ADC_CHANNEL ADC_Channel_2 ...

    ADC_RegularChannelConfig(BSP_ECG2_ANALOG_INPUT_ADC_NUM,

                             BSP_ECG2_ANALOG_INPUT_ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);    

    ADC_Cmd(BSP_ECG2_ANALOG_INPUT_ADC_NUM, ENABLE);

    

}

2 REPLIES 2
Posted on July 01, 2015 at 04:09

Without the defines it's just a jumbled mess. Suggest you spend 5 minutes and code a clean free standing example from scratch where you explicitly code the pins, channel and adc, and test that. If that duplicates the behaviour you are seeing start digging at the hardware, if it works properly look at your defines.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
doreen
Associate II
Posted on July 07, 2015 at 00:35

  Wrote a separate ecg2_init and changed to use ADC2 ADC_Channel_2 now works fine.