2020-09-11 02:22 PM
I'm using the stm32f030k6t6 microprocessor without the devkit, just the module, and I'm using cubeIDE (cubeMX V6.0.1) to generate a code to read a temperature from a sensor connected to PB0 (ADC_IN8). The problem is that when I start the adc (HAL_ADC_Start(&hadc)), stm32 is resetting. I already try using interrupt, DMA, everything, but with no success.
The ADC configuration is:
static void MX_ADC_Init(void)
{
/* USER CODE BEGIN ADC_Init 0 */
/* USER CODE END ADC_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC_Init 1 */
/* USER CODE END ADC_Init 1 */
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
Error_Handler();
}
/** Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC_Init 2 */
/* USER CODE END ADC_Init 2 */
}
If I try to use the assynchronous clock mode, stm32 failed in SystemClock_Config(). I'm using the internal clock 8MHz.
In main I have:
while(1){
HAL_ADC_Start(&hadc);
if (HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY) == HAL_OK){
adc_value = HAL_ADC_GetValue(&hadc);
}
}
But did not pass the HAL_ADC_Start. Using debug, the resetting happens here:
#define __HAL_ADC_ENABLE(__HANDLE__) \
((__HANDLE__)->Instance->CR |= ADC_CR_ADEN)
Thank you!!!
Solved! Go to Solution.
2020-09-11 11:54 PM
> stm32f030k6t6 microprocessor without the devkit, just the module,
What module?
Check power supply with oscilloscope, doesn't its voltage drop when you enable ADC? Are all VDD/VDDA/GND pins connected properly, no bad solder joints, is there adequate decoupling?
JW
2020-09-11 05:01 PM
After it resets, what does the RCC_CSR register say about the source of the reset?
2020-09-11 09:03 PM
Your code is correct. it doesn't have any error.
Adc is not resetting the microcontroller.
you have to check the source of Reset by reading this register.
2020-09-11 11:54 PM
> stm32f030k6t6 microprocessor without the devkit, just the module,
What module?
Check power supply with oscilloscope, doesn't its voltage drop when you enable ADC? Are all VDD/VDDA/GND pins connected properly, no bad solder joints, is there adequate decoupling?
JW
2020-09-12 04:15 AM
If I do not clear the the flags after check one by one, PORRST and SFTRSTF are set. If I clear the flags, SFTRSTF flag is set after reset. I'm using stlink to debug.
A question: when I use the "debug" option in cubeIDE, the code is uploaded and the debug "starts", correct? This can set some of these flags and influencing in the result?
2020-09-12 04:50 AM
Just the microprocessor. I made my own board to a specific solution.
But I checked the VDDA, and it was not connected! And as suggested by TDK and sanju, I checked the RCC_CSR register, and PORSTF and SFTRSTF are set. I connect VDDA to 3.3V and it works!!
Thank you very much guys!!!