Skip to main content
Visitor II
March 11, 2024
Solved

STM32L151 ADC

  • March 11, 2024
  • 1 reply
  • 804 views

I am working with the above device. I have created an .IOC file and auto-generated code. I can see the GPIO configuration for the simple I/O, but I do not see any pin configuration for the ADC inputs that I have selected. I assume that I will have to add these to the MX_ADC_Init module.

I have attached the .IOC file that I have created.

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello,

    They are generated in stm32l1xx_hal_msp.c file in HAL_ADC_MspInit():

     

     /**ADC GPIO Configuration
     PF6 ------> ADC_IN27
     PF7 ------> ADC_IN28
     PC1 ------> ADC_IN11
     PC2 ------> ADC_IN12
     PC3 ------> ADC_IN13
     PA0-WKUP1 ------> ADC_IN0
     PA1 ------> ADC_IN1
     */
     GPIO_InitStruct.Pin = VCC_12V_Pin|VCC_3V3_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
    
     GPIO_InitStruct.Pin = TEMPERATURE_Pin|TEMPA_Pin|TEMPB_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
    
     GPIO_InitStruct.Pin = ISENSE_3V3_Pin|ISENSE_12V_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

     

    Note that HAL_ADC_MspInit() is called by HAL_ADC_Init() which in turn called by MX_ADC_Init()

    1 reply

    mƎALLEmAnswer
    Technical Moderator
    March 11, 2024

    Hello,

    They are generated in stm32l1xx_hal_msp.c file in HAL_ADC_MspInit():

     

     /**ADC GPIO Configuration
     PF6 ------> ADC_IN27
     PF7 ------> ADC_IN28
     PC1 ------> ADC_IN11
     PC2 ------> ADC_IN12
     PC3 ------> ADC_IN13
     PA0-WKUP1 ------> ADC_IN0
     PA1 ------> ADC_IN1
     */
     GPIO_InitStruct.Pin = VCC_12V_Pin|VCC_3V3_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
    
     GPIO_InitStruct.Pin = TEMPERATURE_Pin|TEMPA_Pin|TEMPB_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
    
     GPIO_InitStruct.Pin = ISENSE_3V3_Pin|ISENSE_12V_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

     

    Note that HAL_ADC_MspInit() is called by HAL_ADC_Init() which in turn called by MX_ADC_Init()