cancel
Showing results for 
Search instead for 
Did you mean: 

Reading ADC1 Through STM32MP157F-DK2

Danb127
Visitor

Hi, I’m new to the stm32mp15 series and I’ve been trying to convert code over from a previous microcontroller (stm32f429i-disc1) onto my new MPU. I try to read an input voltage value by running the HAL_ADC_GetValue driver but when I run live expressions to read the variable for my adc value, it is just maxed out at whatever I set the resolution to be (i.e., ADC1 resolution is 12 bits so the value is stuck at 4095). I use STM32CubeMX right now, I enabled continuous conversions but I get stuck at this 4095 value every time I debug and run. Any help or suggestions?

3 REPLIES 3
Danb127
Visitor

To add more info, I am connecting through input channel 1, single-ended mode. I have a wire hooked up to ANA0 and the breadboard and the voltage signal in series with it. 

wkt_1
Visitor

 

It sounds like you're encountering an issue with your ADC configuration on the STM32MP15 series MPU. Here are some steps and considerations to help you troubleshoot and resolve the issue:

1. Check ADC Configuration in STM32CubeMX

  • Resolution: Ensure that the ADC resolution is correctly set to 12 bits in STM32CubeMX.
  • Continuous Conversion Mode: Verify that the continuous conversion mode is enabled. This ensures that the ADC continuously samples and updates the conversion result.
  • Channel Configuration: Double-check that the correct ADC channel is selected and configured for the input you are trying to measure.
  • Sampling Time: Make sure the sampling time is set appropriately for the input voltage and ADC channel.

2. Verify ADC Initialization

Ensure that the ADC is correctly initialized in your code. Typically, this involves:

  • Calling the HAL_ADC_Init() function to initialize the ADC with the settings configured in STM32CubeMX.
  • Setting up the ADC channel with HAL_ADC_ConfigChannel().
  • Starting the ADC with HAL_ADC_Start().

3. Check ADC Read Code

Verify that your ADC read code is correctly implemented. The HAL_ADC_GetValue() function should be used after starting the ADC conversion. Here’s an example of how you might do this:

 

c
Copy code
// Start ADC conversion HAL_ADC_Start(&hadc1); // Wait until the conversion is complete HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY); // Get the ADC value uint32_t adcValue = HAL_ADC_GetValue(&hadc1);
 

4. Check for Common Issues

  • Input Connection: Ensure that the ADC input pin is correctly connected to a valid signal. If the input is floating or not connected properly, it might cause the ADC to read maximum values.
  • Analog/Digital Connections: Verify that there are no issues with the analog-to-digital connections and that the input voltage is within the expected range.
  • ADC Calibration: Sometimes, ADC calibration might be needed. Ensure that the ADC is properly calibrated if this is required.

5. Inspect with Debugger

Use the debugger to:

  • Check ADC Registers: Inspect the ADC configuration registers to ensure they match the settings you expect.
  • Monitor Input Voltage: Use a multimeter or oscilloscope to verify the input voltage to the ADC pin and compare it with the value read by the ADC.

6. Test with Different Input

Try applying a different known voltage to the ADC input to see if the value changes. This can help determine if the issue is with the ADC configuration or the input signal.

7. Review STM32MP15 Documentation

Refer to the STM32MP15 series reference manual and datasheet for any MPU-specific details or differences in ADC handling compared to the STM32F429 microcontroller. The ADC peripheral might have different configurations or requirements on the STM32MP15.

8. Consult STM32 Community and Support

If the issue persists, consider reaching out to the STM32 community forums or STMicroelectronics support for further assistance. They might have encountered similar issues and can provide additional insights.

By systematically checking each of these aspects, you should be able to identify and resolve the issue with your ADC configuration.

So I have ADC1 initialized here:

/* Initialize all configured peripherals */

MX_GPIO_Init();

 

T

hen below here is my ADC1 interrupt handler:

void ADC1_IRQHandler(void)

{

/* USER CODE BEGIN ADC1_IRQn 0 */

// Check if end of conversion flag for the analog voltage has been set

 

adc1_value = HAL_ADC_GetValue(&hadc1);

latest_pressure = Pressure_Calc(adc1_value);

 

/* USER CODE END ADC1_IRQn 0 */

HAL_ADC_IRQHandler(&hadc1);

/* USER CODE BEGIN ADC1_IRQn 1 */

 

/* USER CODE END ADC1_IRQn 1 */

}

With all this being said, I continue to get stuck at the value of 4095 in the case of a 12-bit resolution and I am converting this ADC value into a voltage. I have also tried a 16-bit resolution and get stuck at 65,535. while changing the 4096.0f value to 65,535.0f

(

// Calculate voltage from adc input

result.voltage = (float)adc1_value * (3.3f / 4096.0f);)

which also reads incorrect, all while using a scope to ensure the voltage reading from the component is correct which it is. My only problem now lies in reading it correctly on the MPU.