2025-04-07 1:13 AM - last edited on 2025-04-07 3:19 AM by Andrew Neil
and main.c code is as follows.
After debugging, I confirmed through the live expression window that current_index changes periodically due to the timer interrupt.
I wrote code that processes the keyPressed value based on row input only when a specific current_index (i.e., a specific column is HIGH), using statements like if (current_index == 0); for each value from 0 to 3.
However, in the live expression window, I observed that keyPressed keeps changing sequentially from '1' to 'D' at every timer cycle, even without pressing any key. Eventually, the message “failed to evaluate expression” appeared, and I couldn’t monitor the value anymore.
Question 1. Is the above code appropriate for the keypad behavior I want (i.e., when I press '1', '1' is stored in keyPressed, and when I press '*', '*' is stored)?
Question 2. How can I solve the “failed to evaluate expression” issue?
I’ve already tried “freshen all files,” rebuild, and adjusting the debug level, but nothing worked.
I’d really appreciate your help…
2025-04-07 3:16 AM - edited 2025-04-07 3:17 AM
In the main.c code you attached, there is nothing calling ScanKeypad() so the compiler has optimised away all of it's resources, hence why you get "failed to evaluate expression..."
Also, the current method you are using has a massive race-condition. (Assuming you call ScanKeypad in a loop somewhere)
The timer could fire at any time, including while the proecessor is executing ScanKeypad...
It could fire (and change which pin is HIGH) in between any statement anywhere.
So you need to either stop the timer before each scan or move the code to scan the keyboard into the Timer routine.