Skip to main content

Subsection 7.1.9 Part 5: Choosing the Right Tool

Each of these tools answers a different kind of question. The table below matches a symptom to the tool to reach for:
Table 7.1.15. Which tool, when
Symptom Reach for
Will not build Compiler messages: top down, read up
Runs, but a value is wrong or missing printf placed to answer one question
Need to see a register or step a line Debugger: SFRs, stepping, breakpoints
Suspect the circuit, not the code Digital multimeter (DMM) and Analog Discovery 2 (AD2); the checklist is in the Reference section
A breakpoint stops the processor, so anything that depends on real-time behavior stops with it: a paused chip cannot blink, sample, or keep time. For a timing question the oscilloscope is the better tool, because it watches the pins without pausing the program. We’ll come back to this when we start using interrupts.
These tools are also how you check code you did not write, including code an AI tool drafted for you. The course policy (AI Policy for ENGS 28) asks you to be able to explain every line you submit; the compiler’s report, a well-placed printf, and a register audit in the debugger are the tooling that lets you find out whether you can.
You can now apply all of this in Lab 4.

Activity 7.1.9. Stretch: Debug Your Actual Lab.

Finished the walkthrough with time to spare? Use the same tools on your own Lab 4 program.

(a)

Launch your ADCPot.c under the debugger. Set a breakpoint on the line after the EOC (end of conversion) wait, and watch ADC_DR in the SFRs view while you turn the potentiometer between stops.

(b)

Then audit your own initialization: halt after pa0_adc_init() and check ADC_CHSELR and ADC_CR against what your code claims to have written. Does every bit you set actually read back set?