I’m working on a library to control an 8x8 dot LED matrix with two 8bit shift registers (74hc595). I installed the avr-debugger library and configured my project by following the instructions on pg. 88 of the debugger documentation.
So I start the debug, the board resets a couple of times before the debug actually starts and the debugger goes through the delay function. When I don’t have any breakpoints all works as expected.
The problem - when I put a breakpoint in the lightSingle function I’m testing, the col variable changes and gets assigned some weird value on line 37. I’m guessing it’s something to do with the bitwise operator (the row variable was also changing when I had a similar bitwise shift on line 36).
This is what’s going on with the breakpoints. The code doesn’t recover from then on, the LEDs light up incorrectly until I reset the board:
https://i.imgur.com/OOrEBz6.png
https://i.imgur.com/ERAhMNk.png
Would appreciate if someone has an explanation of what’s going on here.
Here’s the loop and function code:
void loop()
{
for (int i = 1; i <= 8; i++)
{
for (int j = 1; j <= 8; j++)
{
ledMatrix->lightSingle(i, j);
delay(500);
}
}
}
const int activeRowValue[] = {254, 253, 251, 247, 239, 223, 191, 127};
void LedMatrix::lightSingle(int row, int col)
{
if (row < 1 || row > 8 || col < 1 || col > 8)
{
return;
}
int activeRow = activeRowValue[row - 1];
int activeCols = (1 << (col - 1));
shiftOut(_rowSer, _rowSrclk, MSBFIRST, activeRow);
shiftOut(_colSer, _colSrclk, MSBFIRST, activeCols);
digitalWrite(_rowRclk, HIGH);
digitalWrite(_colRclk, HIGH);
digitalWrite(_rowRclk, LOW);
digitalWrite(_colRclk, LOW);
}
platformio.ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps = jdolinay/avr-debugger@^1.5
; added for avr-debugger
build_type = debug
debug_tool = avr-stub
debug_port = COM3
debug_build_flags =
-Og
-g2
-DDEBUG
-DAVR8_BREAKPOINT_MODE=1