Hi, I have the attached code running on a breadboard mounted atmega328. (It is handling the running of a stepper motor)
The incoming serial coms are delivered from a spark photon. I set it up this way because driving a stepper and running other stuff that invokes long delays (a few ms) was causing issues running the stepper motor smoothly.
The first run once is delivered when the photon connects to wifi so the Arduino knows its ready.
Everything works as expected but I noticed yesterday while I was working on the Photon code that the atmega328 code seems to stop working around the 10-20 min mark when idle.
The code is a bit hefty but when idle you can see that what should be happening is as follows:
check_serial() —> if (serial.available) should be False so Nothing happens
motor_operation() —> switch (motor_status) should be case 0 which is empty so Nothing happens
switch (running_state) —> should be case 0 which is empty so Nothing happens
calibrate() —> calibrating = digitalRead(calibration_pin) —> if (calibrating) should be false so Nothing happens
So as follows, I can’t see what might be causing a crash or overflow. All variables are unchanged so the only thing that is happening constantly I suppose is that digitalRead. Could that cause the issue or perhaps there is something else I have missed.
I am fairly confident that motor_status == 0 & running_state == 0 at this point because otherwise, I would see some operation of my motor.
Any advice would be greatly appreciated.
Stepper_Slave_V2.ino (7.52 KB)