Regarding the issue that the chip using STM32G431CBU6 cannot be read by ADC #2970
Replies: 4 comments 1 reply
-
|
Hi @JingtaiChen |
Beta Was this translation helpful? Give feedback.
-
|
Looking at the variant of the STM32G431CBU6 and a dedicated B_G431B_ESC1 is supported. I think it is a clock config issue. void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {};
/* Configure the main internal regulator output voltage */
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);
/* Initializes the CPU, AHB and APB busses clocks */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
RCC_OscInitStruct.PLL.PLLN = 85;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/* Initializes the CPU, AHB and APB busses 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_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8) != HAL_OK) {
Error_Handler();
}
/* Initializes the peripherals clocks */
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB | RCC_PERIPHCLK_ADC12;
PeriphClkInit.Adc12ClockSelection = RCC_ADC12CLKSOURCE_SYSCLK;
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
Error_Handler();
}
}
|
Beta Was this translation helpful? Give feedback.
-
|
The PCB did not use a variant, and the crystal oscillator is 8MHz,I tried your method and called SystemClock_Config() in setup(); Failed to succeed. |
Beta Was this translation helpful? Give feedback.
-
|
Ok. Thank you for the direction you gave. I also think it's a problem with the clock configuration. I'll try again |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Regarding the issue that the chip using STM32G431CBU6 cannot be read by ADC
Hello, recently I have been using the STM32G431CBU6 and found that the ADC cannot be used in the Arduino environment. The read value is always 0. I don't have any other computer to test it, but I tried to use CubeIDE to read the same pin. CubeIDE has no problem and can read the value. Here I attach my program.
‘’
HardwareSerial Serial1(PA10, PA9);
void setup()
{
Serial1.begin(115200);
// analogReadResolution(12);
}
void loop()
{
Serial1.println(analogRead(PA0));
delay(200);
}
‘’
Beta Was this translation helpful? Give feedback.
All reactions