I have a problem that after a small piece of code the Arduoino (UNO)
does no reset. It resets only by uploading a new sketch or by power off.
In the code below I separated the problem to % operation. My idea
was to give exact 1 second signal compared to last reset. I can go
around the problem by other ways, but I'm worried about why this peace of code has a problem. Because I got the same problem in longer code but occasionally (when interrupt happens during %).
My guess is that if reset or interrupt happens during % then the board is somehow in unknown state and does not reset.
The problem can be repeated by code below and pressing the reset button repeatedly until led in line 13 remains blinking. Then the Arduiono is possible to reset only by new sketch or power on.
#include <Wire.h>
#include <string.h>
#undef int
#include <stdio.h>
const int dummyPort = 7;
void setup() {
Serial.begin(115200);
Serial.println("Start Arduino");
pinMode(dummyPort, OUTPUT);
}
unsigned long n1000 = 0;
int dOn = 0;
void loop() {
n1000 = micros() % 1000000;
if ( !dOn && n1000 >= 500000 ) {
digitalWrite(dummyPort, 1);
dOn = 1;
}
if ( dOn && n1000 < 500000 ) {
digitalWrite(dummyPort, 0);
dOn = 0;
}
}
:o