I'm using a Nano, programming with AVRstudio4 and the ISP and monitoring with Realterm.
If I disable DTR in RealTerm, the ATMEGA does not get reset on connection. Looks like the DTR resets the comms chip and the ATMEGA.
Something else however, semi random is resetting the program.
Here is sample corrupted data.
:327.0.0.35.58. :328.0.0.35.55. :329.59304.0.37.5šù:0.0.0.35.58. :1.57331.0.35.56. :2.56494.0.36.57. :3.55558.0.34.57. :4.54761.0.34.57. :5.54018.0.35.57.
Then again a bit later.
:291.0.0.37.57. :292.0.0.37.58. :293.58583.0.36.µþ:0.0.0.36.57. :1.56855.0.36.58. :2.55898.0.36.57.
The data is Line counter, timer value1, Timer value2, ADC1, ADC2.
So my question really is, how can a ATMEGA be reset mid stream? It always resets/faults the program at the end of the send string. I've tried commenting out the ADC conversions and sending 0 but it still faults.
I don't know enough about it, but it looks like a stack fault.
Aha - I found this code for catching missing ISRs and added in the send '?'
ISR(BADISR_vect)
{
send_byte('?');
}
So I'm getting an ISR in the send routine. Here is my new data.
I'm getting a ? after the block.
:602.0.0.31.52.
:603.58485.0.30.52.?
:604.0.0.33.50.
:605.55807.0.31.52.
PS The ATMEGA is now not being reset. Now just have to find out what ISR it is. Tomorrows job. It's late here in NZ.
Fixed. I have not enabled ISRs before but needed to to use the hardware interrupt in this case. What I didn't realize that when the counter, on occasion, overflowed, it did not have an ISR routine to go to and crashed the code. This was picked up with ISR(BADISR_vect).
I then made an ISR(TIMER1_OVF_vect) routine that send out a'T' and that confirmed my findings.
So the first reset was by receiving a DTR from the receiving software, (not a train smash) and the second by ensuring any ISR triggered has a valid place to go.
I've really learned something here.
Thanks to all.