Pages: [1]   Go Down
Author Topic: Leonardo doesn't send to Serial Monitor after software reset  (Read 1145 times)
0 Members and 1 Guest are viewing this topic.
New Jersey
Offline Offline
God Member
*****
Karma: 2
Posts: 525
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8854
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34165
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8854
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
void SlapTheWatchdog(void)
{
    WDTCR=0x18;
    WDTCR=0x08;
    #asm("wdr")
    while(1);
}
Logged

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

New Jersey
Offline Offline
God Member
*****
Karma: 2
Posts: 525
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)?

Attached is my sketch.  The watch dog timer is disabled, you'll need to uncomment // #define WDT on line 17 of Humidity_716Basement_v2.ino to enable the WDT.

* Humidity_716Basement_v2.ino (8.33 KB - downloaded 8 times.)
* WDT.ino (3.57 KB - downloaded 9 times.)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
blink. blink. blink. blink. blink.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

ScottG, how soon after the reset are you opening the Serial Monitor?  If you open the monitor while the bootloader is running it will happily connect but then be orphaned when the bootloader ends and the sketch starts.  Unfortunately there is no indication that this has happened, you just end up with a monitor window that is attached to a port that doesn't exist anymore.
Logged

Pages: [1]   Go Up
Jump to: