Problem with reading ADC Values STM32

Thread Starter

microcontroller60

Joined Oct 1, 2019
62
Hello everyone,

I am currently working on an STM32 project where I'm trying to read ADC values and print them using the printf function. However, I'm facing issues with getting the ADC values to print correctly. I'd like to ask for your help in understanding and resolving this problem. why I'm not able to see the ADC values printed in the console

Setup:

  • Microcontroller board: STM32F407xx
  • Development Environment: STM32CubeIDE
  • Compiler: ARM GCC
  • Debugger: ST-Link


Hardware Setup:

  • Connected one end of the potentiometer to 3.3V (VCC).
  • Connected the other end of the potentiometer to GND.
  • Connect the wiper (middle pin) of the potentiometer to one of the ADC input pins on the STM32F407 board. PA0 pin.

I only see message "ADC !" on terminal

C:
#include "main.h"
#include "usb_host.h"
#include <stdio.h>

ADC_HandleTypeDef hadc1;
UART_HandleTypeDef huart2;


// Private function prototypes
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_ADC1_Init(void);

static void MX_USART2_UART_Init(void);
void MX_USB_HOST_Process(void);


int main(void)
{

  HAL_Init();


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

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_USART2_UART_Init();
  MX_USB_HOST_Init();

  uint32_t adcValue = 0;
  char txData[] = "ADC !\r\n"; // Data to be transmitted

  while (1)
  {
    /* USER CODE END WHILE */
    MX_USB_HOST_Process();
    HAL_UART_Transmit(&huart2, (uint8_t*)txData, strlen(txData), HAL_MAX_DELAY);

    // Start ADC conversion
        HAL_ADC_Start(&hadc1);

        // Wait for the conversion to complete
        HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);

        // Get the ADC value
        adcValue = HAL_ADC_GetValue(&hadc1);

        // Print the ADC value using UART
        printf("ADC Value: %lu\r\n", adcValue);

        // Delay before the next conversion (optional)
        HAL_Delay(1000); // Delay for 1 second

  }

}


void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief ADC1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_ADC1_Init(void)
{

  /* USER CODE BEGIN ADC1_Init 0 */

  /* USER CODE END ADC1_Init 0 */

  ADC_ChannelConfTypeDef sConfig = {0};

  /* USER CODE BEGIN ADC1_Init 1 */

  /* USER CODE END ADC1_Init 1 */

  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.ScanConvMode = DISABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  */
  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief USART2 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART2_UART_Init(void)
{
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }

}

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOE_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
                          |Audio_RST_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : CS_I2C_SPI_Pin */
  GPIO_InitStruct.Pin = CS_I2C_SPI_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
  GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PDM_OUT_Pin */
  GPIO_InitStruct.Pin = PDM_OUT_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : BOOT1_Pin */
  GPIO_InitStruct.Pin = BOOT1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : CLK_IN_Pin */
  GPIO_InitStruct.Pin = CLK_IN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  HAL_GPIO_Init(CLK_IN_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin
                           Audio_RST_Pin */
  GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
                          |Audio_RST_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
  GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : MEMS_INT2_Pin */
  GPIO_InitStruct.Pin = MEMS_INT2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(MEMS_INT2_GPIO_Port, &GPIO_InitStruct);

}


void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
I would greatly appreciate your help
 

HAL9001

Joined Aug 24, 2023
2
The printf function in the standard library calls a _write() function which calls __io_putchar(). without trying to go into too much detail about it, you need to either create your own __io_putchar or _write function that takes the data pointer, and sends it out over uart. Example below:

Stick this in main.c above main()

Code:
int _write(int file, char *ptr, int len) {
    HAL_UART_Transmit(&huart2, (uint8_t *)ptr,len,HAL_MAX_DELAY);
    return len;
}
 

MrChips

Joined Oct 2, 2009
34,629
Your problem relates to how you are creating character arrays.

C:
char txData[] = "ADC !\r\n"; // Data to be transmitted

adcValue = HAL_ADC_GetValue(&hadc1);

printf("ADC Value: %lu\r\n", adcValue);

Instead of mixing up character arrays and integer values, start off with just printing integer values.

C:
uint16_t adcValue;

printf("ADC Value: %d\r\n", adcValue);
 

Thread Starter

microcontroller60

Joined Oct 1, 2019
62
Instead of mixing up character arrays and integer values, start off with just printing integer values.

C:
uint16_t adcValue;

printf("ADC Value: %d\r\n", adcValue);
I used first array to make sure that uart is working successfully. Later I removed the array and trying to print ADC value but I don't get ADC value
 

Thread Starter

microcontroller60

Joined Oct 1, 2019
62
@MrChips

I'm not seeing any values on the serial terminal, and I suspect there might be an issue with my ADC code.
I'd really appreciate it if some of the experts here could take a look at my code and provide some insights. If you spot any mistakes or have suggestions on what I should check, please let me know.

Thank you in advance!
 

HAL9001

Joined Aug 24, 2023
2
@MrChips

I'm not seeing any values on the serial terminal, and I suspect there might be an issue with my ADC code.
I'd really appreciate it if some of the experts here could take a look at my code and provide some insights. If you spot any mistakes or have suggestions on what I should check, please let me know.

Thank you in advance!

Your print statement is failing to send out over the uart. Overwrite the _write function(detailed above) and see if it works. Your print statement is likely trying to go out the wrong port. I copied your print statement and nothing appears to be incorrect, it functions on my board with a project I have already setup.

Your other option is to use sprintf and then send it over uart that you know works.
 

Thread Starter

microcontroller60

Joined Oct 1, 2019
62
Your other option is to use sprintf and then send it over uart that you know works.
Interestingly, when I use the sprintf function to format the ADC value into a string and then send it over UART, everything works perfectly fine. I don't know about what might be causing with print statement .

Here's a my code:


C:
#include "main.h"
#include "usb_host.h"
#include <stdio.h>

ADC_HandleTypeDef hadc1;
UART_HandleTypeDef huart2;


// Private function prototypes
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_ADC1_Init(void);

static void MX_USART2_UART_Init(void);
void MX_USB_HOST_Process(void);

int _write(int file, char *ptr, int len)
{
    int i;

    for (i = 0; i < len; i++)
    {
        HAL_UART_Transmit(&huart2, (uint8_t *)&ptr[i], 1, HAL_MAX_DELAY);
    }

    return len;
}



int main(void)
{

  HAL_Init();


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

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_USART2_UART_Init();
  MX_USB_HOST_Init();

  uint32_t adcValue = 0;


  char txBuffer[50]; // Adjust the buffer size as needed

  while (1)
  {
      MX_USB_HOST_Process();

      // Start ADC conversion
      HAL_ADC_Start(&hadc1);

      // Wait for the conversion to complete
      HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);

      // Get the ADC value
      adcValue = HAL_ADC_GetValue(&hadc1);

      // Format ADC value into a string
      sprintf(txBuffer, "ADC Value: %lu\r\n", adcValue);

      // Transmit the formatted string over UART
      HAL_UART_Transmit(&huart2, (uint8_t *)txBuffer, strlen(txBuffer), HAL_MAX_DELAY);

      // Delay before the next conversion
      HAL_Delay(1000); // Delay for 1 second
  }

}


void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief ADC1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_ADC1_Init(void)
{

  /* USER CODE BEGIN ADC1_Init 0 */

  /* USER CODE END ADC1_Init 0 */

  ADC_ChannelConfTypeDef sConfig = {0};

  /* USER CODE BEGIN ADC1_Init 1 */

  /* USER CODE END ADC1_Init 1 */

  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.ScanConvMode = DISABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  */
  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief USART2 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART2_UART_Init(void)
{
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }

}

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOE_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
                          |Audio_RST_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : CS_I2C_SPI_Pin */
  GPIO_InitStruct.Pin = CS_I2C_SPI_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
  GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PDM_OUT_Pin */
  GPIO_InitStruct.Pin = PDM_OUT_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : BOOT1_Pin */
  GPIO_InitStruct.Pin = BOOT1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : CLK_IN_Pin */
  GPIO_InitStruct.Pin = CLK_IN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  HAL_GPIO_Init(CLK_IN_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin
                           Audio_RST_Pin */
  GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
                          |Audio_RST_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
  GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : MEMS_INT2_Pin */
  GPIO_InitStruct.Pin = MEMS_INT2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(MEMS_INT2_GPIO_Port, &GPIO_InitStruct);

}


void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
Code:
ADC Value: 3214
ADC Value: 3212
ADC Value: 3216
ADC Value: 3212
ADC Value: 3214
ADC Value: 3211
ADC Value: 0
ADC Value: 12
ADC Value: 1
ADC Value: 0
ADC Value: 33
ADC Value: 37
ADC Value: 22
ADC Value: 32
ADC Value: 0
ADC Value: 34
ADC Value: 34
ADC Value: 0
ADC Value: 49
ADC Value: 0
ADC Value: 14
ADC Value: 0
ADC Value: 3838
ADC Value: 3839
ADC Value: 3842
ADC Value: 3850
ADC Value: 3838
ADC Value: 3848
ADC Value: 3839
ADC Value: 3835
ADC Value: 3836
ADC Value: 3839
ADC Value: 3839
ADC Value: 18
ADC Value: 39
ADC Value: 0
ADC Value: 4
ADC Value: 0
ADC Value: 3847
ADC Value: 9
ADC Value: 4
ADC Value: 10
ADC Value: 13
ADC Value: 0
ADC Value: 13
ADC Value: 5
ADC Value: 18
ADC Value: 5
ADC Value: 5
ADC Value: 10
ADC Value: 7
ADC Value: 8
ADC Value: 4
ADC Value: 6
ADC Value: 2
ADC Value: 5
ADC Value: 8
ADC Value: 0
ADC Value: 7
ADC Value: 3
ADC Value: 5
ADC Value: 8
ADC Value: 9
ADC Value: 8
ADC Value: 2
ADC Value: 8
ADC Value: 4
ADC Value: 4
ADC Value: 11
ADC Value: 29
ADC Value: 12
ADC Value: 12
ADC Value: 5
ADC Value: 10
ADC Value: 28
ADC Value: 4
ADC Value: 21
ADC Value: 10
ADC Value: 4
ADC Value: 3922
ADC Value: 7
ADC Value: 3
ADC Value: 13
ADC Value: 4
ADC Value: 3934
ADC Value: 3918
ADC Value: 3915
ADC Value: 3923
ADC Value: 3915
ADC Value: 3922
ADC Value: 3928
ADC Value: 3926
ADC Value: 3917
ADC Value: 3928
ADC Value: 1
ADC Value: 12
ADC Value: 10
ADC Value: 0
ADC Value: 11
ADC Value: 0
ADC Value: 0
ADC Value: 22
ADC Value: 6
ADC Value: 0
ADC Value: 25
ADC Value: 28
ADC Value: 24
ADC Value: 14
ADC Value: 40
ADC Value: 16
ADC Value: 4
ADC Value: 20
ADC Value: 2212
ADC Value: 2708
ADC Value: 2675
ADC Value: 2747
ADC Value: 0
ADC Value: 0
ADC Value: 22
ADC Value: 0
ADC Value: 6
ADC Value: 14
ADC Value: 19
ADC Value: 4
ADC Value: 0
ADC Value: 0
ADC Value: 4
ADC Value: 8
ADC Value: 9
ADC Value: 11
ADC Value: 0
ADC Value: 4
ADC Value: 9
ADC Value: 13
ADC Value: 14
ADC Value: 7
ADC Value: 4
ADC Value: 21
ADC Value: 3321
ADC Value: 3320
ADC Value: 3306
ADC Value: 3318
ADC Value: 3303
ADC Value: 3316
ADC Value: 6
ADC Value: 0
ADC Value: 6
ADC Value: 4
ADC Value: 7
ADC Value: 9
ADC Value: 4
ADC Value: 8
ADC Value: 8
ADC Value: 7
ADC Value: 8
ADC Value: 5
ADC Value: 8
ADC Value: 9
ADC Value: 17
ADC Value: 6
ADC Value: 13
ADC Value: 10
ADC Value: 2
ADC Value: 10
ADC Value: 10
ADC Value: 6
ADC Value: 12
ADC Value: 7
ADC Value: 0
ADC Value: 11
ADC Value: 2
ADC Value: 13
ADC Value: 6
ADC Value: 0
ADC Value: 8
ADC Value: 6
ADC Value: 6
ADC Value: 14
ADC Value: 6
ADC Value: 2
ADC Value: 6
ADC Value: 11
ADC Value: 5
ADC Value: 8
ADC Value: 12
ADC Value: 5
ADC Value: 8
ADC Value: 2
ADC Value: 4
ADC Value: 8
ADC Value: 12
ADC Value: 5
ADC Value: 7
ADC Value: 7
ADC Value: 8
ADC Value: 3
ADC Value: 0
ADC Value: 7
ADC Value: 2
ADC Value: 8
ADC Value: 8
ADC Value: 10
ADC Value: 9
ADC Value: 6
ADC Value: 8
ADC Value: 16
ADC Value: 6
ADC Value: 8
ADC Value: 5
ADC Value: 4
ADC Value: 2
ADC Value: 7
ADC Value: 6
ADC Value: 5
ADC Value: 9
ADC Value: 13
ADC Value: 2
ADC Value: 0
ADC Value: 9
ADC Value: 9
ADC Value: 7
ADC Value: 2
ADC Value: 8
ADC Value: 5
ADC Value: 0
ADC Value: 4
ADC Value: 8
ADC Value: 8
ADC Value: 4
ADC Value: 14
 
Top