Sketch being erased when replugging the USB with RFM95 removed

Started by Wanderer, May 25, 2017, 11:58:03 PM

Wanderer

Hello. I bought the Moteino a month or so ago. Did some test with the LORA modules and had some fun with that. However, recently I've been planning to interface Moteino with another LORA module (that runs on uart and more features). I removed the RFM95. I did this for two Moteinos. One a regular Moteino and the other a Moteino-USB.

I haven't received the other LORA module yet, but I was doing some sample tests regarding the codes. I've been encountering a problem where the sketch is being erased (what I mean by this is the behavior where the Moteino no longer run the sketch I loaded into it) Here's what is working properly and what isn't.

What Works Properly:
- Programming the sketch into the Moteino (through the Moteino FTDI adapter) and the Moteino-USB
- Retaining the sketch for the Moteino if it is unplugged from the FTDI adapter AND re-plugging it into the FTDI adapter while the FTDI adapter remains connected to the USB cable. (FTDI adapter must not be powered off for this to work, so if the FTDI or its cable was removed from the USB and then re-plugged back in, it will result in the Moteino's loaded sketch being removed)

What Fails:
- Replug the USB cable for both Moteino (while it is connected to the FTDI adapter) and the Moteino-USB results in the sketch loaded inside them to be erased. The program becomes a burst of LED flashes every 1-2 seconds.
- Shaking the USB connector of the Moteino-USB a bit while it is connected will result in the sketch being erased (even when it was not really unplugged yet).
- With Moteino unplugged from the FTDI adapter, if the FTDI adapter is removed from the USB and replugged back into the USB port, plugging the Moteino back into the FTDI adapter will result in the sketch in the Moteino being erased.

The only additional library I've used in my sketch right now is SoftwareSerial. I've been doing some IO manipulation and serial send/receive, but that's pretty much it. I've been using GPIO 2, 3, 4, 5, and 9 (for onboard LED). Also, I have tried different USB cables so that shouldn't be the problem.

Right now I can only think of two possible reasons causing this:
- Removal of the radio left some programming IO hanging that causes problems with the USB IC (something triggered the bootloader and erased the sketch inside probably).
- My laptop's USB ports are really messed up.

I wonder if anyone can determine a solution. Thanks.

Felix

Shaking and plugging/replugging USB erases a sketch?
Sounds like you got aliens around!!

JK but I can't imagine how that could happen. How do you verify that the sketch is no longer there?
Or verify that the flash of the AVR is now different than what you loaded? Or blank?
Never seen anything like that happen.

When you say "removed the radio" you mean desoldered? After programming?

Wanderer

Thanks for your help.

What I mean by 'removed the radio' I mean it is desoldered. I've been programming and testing the Moteino with it desoldered.

After some extensive testing, I found out that the program isn't erased. It is just something I didn't realize before with the Arduino IDE.

With the IDE running and serial monitor off, the Moteino runs in programming mode instead of running the sketch loaded on it.
With the IDE running and serial monitor on, the Moteino will run the sketch. When I was talking about the difference between how Moteino and Moteino USB operated, it is because of the serial monitor being on or off. With the USB version, I always turn it off when replugging the USB.
With the IDE not running, the Moteino will run the sketch.

So that being solved, I now run into another problem. This time it is the differences between 'debug' mode vs 'operation' mode. Apparently, my software serial comport behaves differently in debug and operation mode. It works find in debug, but it just doesn't receive data (and thus my code gets stuck in the while loop with .available() waiting for it) properly when I run it without IDE or with a standalone power supply. Yes, removing the while loop will help the code get pass the part where I'm currently stuck in, but that also kills the point of having a transceiver. Maybe I should test it with other pins? I'm currently using Pin 2 as RX and Pin 3 as TX.

Thanks again.

Additional notes:
Further testing with a logic analyzer only revealed that when I connect the logic analyzer's ground (which was on a different USB port on the same computer as Moteino's USB adapter), my program runs fine and can successfully trigger software serial RX. However, once I remove the ground, it stops working and get stuck at that while loop waiting for UART RX data.

Yet another addition note:
After changing the code slightly by adding a three second delay before enabling software serial, I think I have found the main problem about the failure of software serial. I'll admit I made a linear regulator mod by changing the default Moteino LDO to another one with 1A supply support (but at the cost of poorer and longer wiring of course). I guess this power instability may have some toll on the software serial and cause some parts of the code to malfunction (like a ground bounce maybe). When I was testing with my logic analyzer, the moteino ground was already firmly attached through the logic analyzer. When it was plugged in, the power supply was probably more stable than it was. Thus I had no problem testing it with the logic analyzer's ground connected. I'll probably do more tests to find the shortest delay to make things stable, but this should be the end of my question regarding this issue. Thanks again.

Felix

Quote from: Wanderer on May 30, 2017, 11:21:22 PM
After some extensive testing, I found out that the program isn't erased. It is just something I didn't realize before with the Arduino IDE.

Thought so ;)

Can you define what 'debug' mode vs 'operation' mode is?

Wanderer

Quote from: Felix on May 31, 2017, 01:47:40 PM
Thought so ;)

Can you define what 'debug' mode vs 'operation' mode is?

What I mean by debug and operation at the time is actually one and the same (ie. Moteino running the sketch) except that each is run in a different environment and slightly different hardware setup.

What I meant by debug at the time is running the Moteino with the Arduino IDE on and Serial Monitor on. In this test setup, power and ground of the Moteino was already firmly connected to the USB before the sketch was being ran (ie. turning on Serial Mode), thus eliminating any power bounce problems. Also, the Moteino tested in this setup is connected to the FTDI adapter.

What I meant by operation is when I run Moteino with an external 5V power supply in its input power pins and ground. The Moteino is not connected to the computer at all. It is the same as if you run Moteino from a battery pack. I called it operation because this is most likely how I'll be running Moteino when I use it for something. Due to the sudden rush or power, problems like power bounce will become problematic at startup. I had to add a delay in my setup() code to wait for the power to be stabilized to use software serial properly. In this test setup, the Moteino is not connected to any USB adapters (like the FTDI adapter).

Felix

Your Moteino with a LDO mod attached with wires is quite different than an original so this is no longer a support issue.