Go Down

Topic: Leonardo doesn't send to Serial Monitor after software reset (Read 1 time) previous topic - next topic

ScottG

I have Arduino 1.01 and a Leonardo with an Ethernet shield (R3).  My sketch is designed to do a reset if there is a communication problem, to test this I just unplug the cable from the Ethernet shield.  The Arduino resets using  asm volatile ("  jmp 0"); 
The reset works fine and the Arduino continues uploading to COSM.com via the Ethernet shield, but if I had the serial monitor open, I don't see any text after the reset.  Even if I close the serial monitor and re-open it, still nothing.  I know the Leonardo works a little differently then the UNO with the serial monitor.  Is there anything I can do to get the Arduino to recognize the serial monitor after a reset.  The serial monitor works fine when I upload a new sketch, it's just after a reset I have a problem.  I had also tried resetting with the Watch Dog Timer, and I have the same serial monitor issue with that method also.  If I close the serial monitor then do a hard reset (using the PCB pushbutton), the serial monitor works again.


johnwasser

Jumping to the Reset vector does not reset the hardware, it just starts the bootloader.

If you have a spare digital pin you might be able to perform an ACTUAL reset by connecting the digital pin to the Reset pin and setting that pin to LOW and OUTPUT.

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Grumpy_Mike

Quote
If you have a spare digital pin you might be able to perform an ACTUAL reset by connecting the digital pin to the Reset pin and setting that pin to LOW and OUTPUT.

No that will not work. As soon as the reset is activated, the output goes tristate and removes the reset so it will not reset correctly.

@OP :- Is is bad code that requires a hardware reset, you are best writing it correctly.

mellis

I'm surprised that it doesn't work when you use the watchdog timer.  Can you provide more details (e.g. a sample sketch and the behavior you see)?

On the other hand, a "jmp 0" might not work, because it doesn't necessarily shutdown / re-initialize the registers / peripherals / USB connections.  On the Uno, the USB-serial connection is done by a separate chip, so you the connection will stay up regardless of what you do to the main processor (ATmega328).  On the Leonardo, there's just one chip, so you have to be more careful about maintaining the USB connection.

johnwasser

I found this small routine that forces the Watchdog Timer to perform a reset:

Code: [Select]

void SlapTheWatchdog(void)
{
    WDTCR=0x18;
    WDTCR=0x08;
    #asm("wdr")
    while(1);
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up