AnsweredAssumed Answered

Just work ADC when it's debug mode.

Question asked by Takayoshi Ishii on Aug 25, 2017
Latest reply on Aug 28, 2017 by Takayoshi Ishii

Hello,

 

I use STML051 that has a sensor via ADC port. My environment is keil-MDK-v5 and LL Library.

 

My firmware works well when it's debug-mode. But when I download the program and run without debugger, ADC is frozen at

 

ADC1->CR |= ADC_CR_ADSTART;

 

Following is a code of adc that I made. When I do comment-out above line, MCU doesn't freeze.

If I do the same code by debug-mode, It works and I can get the adc value.

 

 

---my code---

 

uint16_t readAdc(void)

{
uint16_t adcResult=0;
Activate_ADC();
ConversionStartPoll_ADC_GrpRegular();
txDelay_1ms();
adcResult = LL_ADC_REG_ReadConversionData12(ADC1);
return adcResult;
}


void Activate_ADC(void)
{
__IO uint32_t wait_loop_index = 0;
if (LL_ADC_IsEnabled(ADC1) == 0)
{
/* Run ADC self calibration */
LL_ADC_StartCalibration(ADC1);
while (LL_ADC_IsCalibrationOnGoing(ADC1) != 0){}

/* Delay between ADC end of calibration and ADC enable. */
wait_loop_index = (ADC_DELAY_CALIB_ENABLE_CPU_CYCLES >> 1);
while(wait_loop_index != 0)
{
wait_loop_index--;
}

/* Enable ADC */
LL_ADC_Enable(ADC1);

/* Poll for ADC ready to convert */
while (LL_ADC_IsActiveFlag_ADRDY(ADC1) == 0){}
}

}


void ConversionStartPoll_ADC_GrpRegular(void)
{

if ((LL_ADC_IsEnabled(ADC1) == 1) &&
(LL_ADC_IsDisableOngoing(ADC1) == 0) &&
(LL_ADC_REG_IsConversionOngoing(ADC1) == 0) )
{
// LL_ADC_REG_StartConversion(ADC1);

/*
MODIFY_REG(ADC1->CR,
ADC_CR_BITS_PROPERTY_RS,
ADC_CR_ADSTART);
*/
ADC1->CR |= ADC_CR_ADSTART;


}
else
{
/* Error: ADC conversion start could not be performed */
errorCode=0x00000023;
}

// while (LL_ADC_IsActiveFlag_EOC(ADC1) == 0){}

 

LL_ADC_ClearFlag_EOC(ADC1);

}

Outcomes