LowPowerLab Forum

Hardware support => Moteino => Topic started by: VdesmedT on October 12, 2015, 06:33:56 AM

Title: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 12, 2015, 06:33:56 AM
Hey guys,

My sketched was working fine when powered up from the FTDI board but fails when powered up by a Lipo connected to vIn...  After investigation, it turns out that the code that fails is the flash.initialize() !  That makes absolutely no sens to me but it seems to be the problem so far.  As anyone experienced something similar ?

those are the lines that were removed :

//SPIFlash flash(8, 0xEF30); //EF30 for 4mbit  Windbond chip (W25X40CL)
//flash.initialize();
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: Felix on October 12, 2015, 08:34:22 AM
So you have a Moteino with FLASH MEM right?
There were some threads about this.
Your D8 may be floating, causing the FLASH MEM chip to not respond. You probably need a 10K pullup to 3.3v on D8. Give that a try and let us know if it's still an issue.
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 12, 2015, 08:39:52 AM
Thanks Felix,

I'll give it a try but why would that only be the case when FTDI is disconnected ?
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: TomWS on October 12, 2015, 08:41:15 AM
@VdesmedT, have you tried to go back to the FTDI (with flash initialize enabled) after trying the LiPo?  My thought was that the LiPo accidentally touched 3.3V pin and fried the flash chip.  I'm struggling to find another potential cause.  Felix's suggestion might be necessary if you weren't using flash initialize.

Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: Felix on October 12, 2015, 08:42:00 AM
Quote from: VdesmedT on October 12, 2015, 08:39:52 AM
Thanks Felix, I'll give it a try but why would that only be the case when FTDI is disconnected ?

You have an earth ground insted of a floating ground which can be influenced by static a lot more.
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 12, 2015, 08:56:10 AM
Quote from: TomWS on October 12, 2015, 08:41:15 AM
@VdesmedT, have you tried to go back to the FTDI (with flash initialize enabled) after trying the LiPo?

I have switched from one to the other many times as my mind couldn't settle on this :-)  Often happens to me..  I have to experience things many times before I actually start to believe it..... 

Thanks though
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: TomWS on October 12, 2015, 09:10:59 AM
Quote from: VdesmedT on October 12, 2015, 08:56:10 AM
Quote from: TomWS on October 12, 2015, 08:41:15 AM
Often happens to me..  I have to experience things many times before I actually start to believe it..... 
LOL!  I hear ya!
Good luck, if I think of anything I'll let you know.  Is it safe to assume that you've checked that the LiPo is charged and you're getting 3.3V at the 3.3V pin?

Tom
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 12, 2015, 10:49:53 AM
Quote from: TomWS on October 12, 2015, 09:10:59 AM
Is it safe to assume that you've checked that the LiPo is charged and you're getting 3.3V at the 3.3V pin?

That also went through my poor mind 8)
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 12, 2015, 04:03:23 PM
Quote from: Felix on October 12, 2015, 08:34:22 AM
Your D8 may be floating, causing the FLASH MEM chip to not respond. You probably need a 10K pullup to 3.3v on D8.

Gave it a try..  same problem, despite the pullup, D8 remains LOW and flash.Initialize does not passes.  I have noticed something strange : while doing my tests, I noticed that if I connect the FTDI in a way that GND is connected first, the same problems happens (and D8 is low) while if I connected the FTDI in away that DTR is connected first, it works (and D* is HIGH)....  rings a bell ?

UPDATE : Seems that connecting the battery then reseting the moteino by pulling DTR down solves the problem
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: Felix on October 12, 2015, 08:44:11 PM
Take a look at this issue (https://github.com/LowPowerLab/SPIFlash/issues/4). It's not the same situation since you do have a SPI FLASH chip (OEM from LowPowerLab).
But it's strikingly similar in behavior. If you have a logic analyzer and/or scope you could start digging into this a lot better than guessing what could be wrong. I have not seen this type of behavior. If you have other SPI devices and libraries that could be a cause. Can you try a stock example sketch (https://github.com/LowPowerLab/SPIFlash/blob/master/examples/SPIFlash_ReadWrite/SPIFlash_ReadWrite.ino) that only initializes the SPIFLASH without any other SPI device attached and observe any difference?
PS. also ensure you got the latest lib code.
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 14, 2015, 03:24:46 AM
Interesting...  I uploaded the stock example sketch, disconnected the moteino from all external circuit and...  same issue :-) I also tried on a bunch of moteino just to check that nothing was wrong with the one I was using..  green test !

So, simply loading the stock example sketch on a moteino and trying different ways to connect the FTDI module (from left to right or from right to left) shows the problem. Also, not using the FTDI to power up the moteino but using the GND/VIN pins from a 3.7 Lipo shows it even better... 

I'll try to debug SPI using my BitScope when I can....

Thanks,
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: Felix on October 14, 2015, 11:15:07 AM
Ok, I have updated the SPIFlash example sketch, I added a fast blinking sequence when flash.initialize() succeeds:

SPIFlash flash(FLASH_SS, 0xEF30);
void setup(){
  Serial.begin(SERIAL_BAUD);
  Serial.print("Start...");

  if (flash.initialize())
  {
    Serial.println("Init OK!");
    Blink(LED, 20, 10);             <------ blinks every time, so initialize() does not fail
  }
  else
    Serial.println("Init FAIL!");
 
  delay(1000);
}


I have tested with a bran new Moteino with FLASHMEM, and the blinking is always presend, no matter how I power it, through FTDI or just through GND-VIN, from battery or from PC etc.

So I cannot replicate the issue you are describing. Until you submit a full analysis and demonstration and point out the code where it fails and why, I will assume there is no issue. In fact if there was such a initialize() issue this would have been raised long ago since the FLASHMEM is essential for several features of Moteino.
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 15, 2015, 04:09:00 PM
Hey there, Sorry Felix, I never meant to suggest that there was a problem with he moteino. It has always be clear to me that I was doing something wrong.  I've created this video to show you what I'm doing.

https://youtu.be/B9eJ-Ckye0M

The first time, the fast blinking does not appears while it does on the second part of the clip.  If you see something obvious that I do wrong, please let me know.

kindest regards,

Valery
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: Felix on October 15, 2015, 08:29:18 PM
Valery,
I thought you said that it works with FTDI and not when powered from VIN+GND. So can you please load my sketch (updated last night) and try again. There is a fast blinking at start of the sketch, then the normal blinking.
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 16, 2015, 08:32:27 AM
Hey felix,

The same problem indeed happens when powering up from Vin. The sketch that you see running is your latest version with the fast blinking that you can berly see happening on the second run (the video fps make it so that you only see a bit longer blink). Have you notice the two different way to plug the FTDI ?
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: Felix on October 16, 2015, 08:35:04 AM
I don't know what to say .. it just works on my end, no issues with my FTDI adapter or with just a battery on VIN...
If you want to return your Moteino for investigation you are welcome to do so and I will compare yours with a vanilla Moteino.
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: VdesmedT on October 16, 2015, 08:38:36 AM
As I said, I'm pretty sure the Moteino is NOT the cause of the problem. I just found it weird I thought I made an obvious mistake that you or anyone with your skills might be able to point out. I will keep on investigate this and let you know when I found the issue..  pretty sure we will have a good laugh at the end  ;D
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: WhiteHare on February 01, 2016, 01:17:27 PM
Did you ever discover the cause or a fix? 

I have just now run into what appears to be the exact same issue on a Moteino R4 with lowpowerlab's factory installed flash memory.  flash.initialize() returns true if I connect using the LowPowerLab FTDI connector but returns false if I don't use the FTDI connector and merely supply power through Vin using four fresh AA batteries in series (equals 6 volts).  Weird with a beard.

[Edit1: After the above, I upgraded to the most current version of lowerpowerlab's SPIFlash library, and the results are the same.  After running some very simple tests, flash memory does appear to not only initialize but also write and read correctly when connected using the FTDI.]

[Edit2: I tried the same thing with a different Moteino R4, and it was 100% reproducible on it as well.]

[Edit3:  I just now tried adding a 10K ohm resistor between D8 and 3.3V, as suggested by Felix above.  No change in results.]

[Edit4:  I just now upgraded to lowpowerlab's latest RFM69 library to see if that might help at all.  Nope.  No change in results.]

[Edit5: Here's the first real clue.  If I power the Moteino from the FTDI by *only* connecting the Vin and Gnd wires, then it's the same as if I powered it with a battery, and I get the same derailed results.  So.. Now I'll try hooking up additional wires until I find the one that makes it work again.]
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: WhiteHare on February 01, 2016, 03:09:10 PM
The answer is: connecting DTR on the Moteino R4 to DTR on the LowPowerLab FTDI allows the flash memory to initialize.

WTF?

[Edit: Hooking up the FTDI's Tx to the Moteino's Rx doesn't "fix" the issue.  Neither does hooking up the FTDI's Rx to the Moteino's Tx.  Only hooking DTR to DTR "fixes" the issue.  However, that's obviously not much of an option if I want to initialize the flash memory when I'm running the Moteino by battery.  So... at least on the face of it, it looks like an electrical problem of some kind.]
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: WhiteHare on February 01, 2016, 03:48:42 PM
Solution: wiring the Moteino R4's DTR pin to ground solves the problem.
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: TomWS on February 01, 2016, 06:20:50 PM
Quote from: WhiteHare on February 01, 2016, 03:48:42 PM
Solution: wiring the Moteino R4's DTR pin to ground solves the problem.
If you search the forum for "DTR to ground" you will find a number of references to this phenomenon, eg, https://lowpowerlab.com/forum/index.php/topic,961.msg7606.html#msg7606

Tom
Title: Re: flash.initialize() fails when powered from vIn... What ???
Post by: Felix on February 01, 2016, 08:46:42 PM
I tried it again, I still can't reproduce this. The radio will initialize with or without battery on my end. I just used a blinky with different blink rates depending on FLASH init result.