When a program builds and runs but misbehaves, the fastest way to answer a question about it is a printf. You have used printf since Day 5, so what we’ll practice today is where to place one.
You get to add exactly oneprintf to ADCPot.c. Decide which line it goes on. There is more than one good answer, but there are many less ideal ones, so commit to yours before reading on.
The greeting printed, so the program runs and printing works. The hang is somewhere after it. The highest-value placement is the first line of pa0_adc_init(): it splits “my init hangs” from “my sample loop hangs”, and one more print halves the remaining half again. That is bisection: each print cuts the region that can still hold the fault in two. (If nothing printed at all, not even the greeting, the usual cause is the one we saw with the ADC program: a stray blinky.c or another unrelated program is what is actually building.)
An ADC count of 0 or 4095 that never changes says configuration; one that jitters near a plausible value says the ADC is fine and the bug is downstream.
Two housekeeping rules from Day 5 still apply: end every printf() string with \r\n, and remember that a 32-bit register needs %08lx (Subsection 7.2.4 collects the patterns). And when the bug is found: take the diagnostic prints out. They slow the loop and clutter the output of the finished program.
/* 1. Did execution reach this point? The greeting printed,
so printing works -- the hang is after it. This print
splits "init hangs" from "loop hangs". Then bisect. */
printf("pa0_adc_init: entered\r\n");
/* 2. Is this value reasonable? Stuck at 0 or 4095 = config;
jitter near a plausible value = look downstream. */
printf("sensor_value = %d\r\n", sensor_value);
/* 3. Does ACTUAL match EXPECTED? Print them side by side. */
printf("sensor_value = %d (expect 0..4095)\r\n", sensor_value);
One print cuts the program in half. Bisection corners the bug in a few builds.