ADC Quick Start (help)

Go To Last Post
2 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


After reading the app note AT03243 SAM Analog to Digital Converter Driver.

I am trying to run the ADC quick start example on the SAMD21Xplained board and it seems to hang in the adc_read function call.


     uint16_t result;


    //get results //
    do {
        /* Wait for conversion to be done and read out result */
    } while (adc_read(&adc_instance, &result) == STATUS_BUSY);


I don't have anything connected to my analog inputs. I was planning to run this in debug mode and observe the "result" variable which should give some reading, however small the reading may be.

I've added "result" to the watch list here is what it shows:



pausing the debugger takes me to this statement in adc.h

    /* Clear interrupt flag */
    adc_module->INTFLAG.reg = int_flags;



Do I really need something connected to the ADC for this to work?  What am I missing? 

thanks in advance.


This topic has a solution.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It appears that the optimization option is enabled.  Since I did not do anything with the "result", it probably got deleted during compile. "<optimized out>" should have been a big clue!

For someone new to ATMEL Studio and ASF, I found this quick start example to be a bit frustrating as the whole program just does a single conversion before entering an endless loop.

Not to mension the default compiler option optimized out the only variable that shows if anything is happening :)


Adding a couple of printf statements to this example is extremely helpful.  Here's a nice reference on how to use printf statements through the embedded debugger.


Hope this helps.