cancel
Showing results for 
Search instead for 
Did you mean: 

Just work ADC when it's debug mode.

Takayoshi Ishii
Associate III
Posted on August 25, 2017 at 17:47

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);

}
3 REPLIES 3
Posted on August 25, 2017 at 17:49

Make sure all clock sources are correctly enabled. Check if ADC on your part requires HSI clocking.

Try to provide a complete example that demonstrates the issue.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
Posted on August 25, 2017 at 20:08

Sanity check: Is in debug mode the program is manually breakpointed (delays)? Is the compile optimisation the same in debug and release mode? sometime it's due to volatile management or because of viewing the HW registers on the debugger... these are the general typical pitfalls 

Takayoshi Ishii
Associate III
Posted on August 28, 2017 at 09:13

Thank you for two guys!

The infomations are good for my experience.

Before, I used interrupt for watching the adc over-run. When I don't use adc interrupt, the problem doesn't happend.

Now, I re-write all of the adc code as not using interrupt, but use polling, then it works well.

Thank you.