LowPowerLab Forum

Hardware support => MoteinoMEGA => Topic started by: G550_Pilot on May 11, 2016, 11:24:35 PM

Title: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: G550_Pilot on May 11, 2016, 11:24:35 PM
I'm sure it is something stupid that I am doing but....

Got a couple of shiny new Megas today and tried to throw PiGateway on them and I am getting the following error:


SPI Flash Init FAIL! (is chip present?)


And I think it is because I do not have this correct:


#define FLASH_CS        8
SPIFlash flash(FLASH_CS, 0xEF40); //EF40 for 16mbit windbond chip


Can someone point me to the right settings for the Mega?


Thanks
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?)
Post by: Felix on May 12, 2016, 10:55:03 AM
Should be 0xEF30 if it's an OEM Moteino+FLASHMEM.
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?)
Post by: TomWS on May 12, 2016, 12:02:35 PM
Quote from: Felix on May 12, 2016, 10:55:03 AM
Should be 0xEF30 if it's an OEM Moteino+FLASHMEM.
Wow, I cut and pasted this directly from Node.ino in the RFM69 library.  Admittedly it's an older version of the library, however...

Tom
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?)
Post by: G550_Pilot on May 12, 2016, 12:38:18 PM
Exact same result on both of the MegaUSBs that I purchased.


SPI Flash Init FAIL! (is chip present?)



With this:

#define FLASH_CS        8
SPIFlash flash(FLASH_CS, 0xEF30); //EF40 for 16mbit windbond chip

Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?)
Post by: Felix on May 12, 2016, 02:39:56 PM
Make sure the CS is correctly set. It is D8 only on Moteinos. On MoteinoMEGAs they are D23:

#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
  #define FLASH_SS      23 // and FLASH SS on D23
#else
  #define LED           9 // Moteinos have LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?)
Post by: G550_Pilot on May 12, 2016, 04:37:03 PM
That did the trick Felix!
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: pedro.albuquerque on May 19, 2016, 05:11:41 PM
I'm having similar problem, certainly some thing basic , nevertheless not able to find what.

I tried to load the SPIFlash_ReadWrite example sketch to a Motion MEGA LORA with SPI Flash

"
#ifdef __AVR_ATmega1284P__
#define LED           15 // Moteino MEGAs have LEDs on D15
#define FLASH_SS      23 // and FLASH SS on D23
#else
#define LED           9 // Moteinos have LEDs on D9
#define FLASH_SS      8 // and FLASH SS on D8
#endif

//////////////////////////////////////////
// flash(SPI_CS, MANUFACTURER_ID)
// SPI_CS          - CS pin attached to SPI flash chip (8 in case of Moteino)
// MANUFACTURER_ID - OPTIONAL, 0x1F44 for adesto(ex atmel) 4mbit flash
//                             0xEF30 for windbond 4mbit flash
//////////////////////////////////////////
SPIFlash flash(FLASH_SS, 0xEF30);

void setup(){
    Serial.begin(SERIAL_BAUD);
    Serial.print("Start...");
   
    if (flash.initialize())
"

But i get an error "Start...Init FAIL!" on Terminal

Any clue on this ?


Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: Felix on May 20, 2016, 09:25:54 AM
I just tested this sketch (https://github.com/LowPowerLab/SPIFlash/blob/master/examples/SPIFlash_ReadWrite/SPIFlash_ReadWrite.ino) and it works just fine.
If the chip is not damaged in some way and all connections look good it should work.
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: pedro.albuquerque on May 22, 2016, 04:55:38 PM
Thanks Felix for confirming,

I tried the sketch on a Motion LR and it worked fine, then repeated on a Motion Mega LR and again it fails... I may have a problem with the flash ship on may Mega board.

Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: TomWS on May 22, 2016, 05:49:58 PM
Quote from: pedro.albuquerque on May 22, 2016, 04:55:38 PM
Thanks Felix for confirming,

I tried the sketch on a Motion LR and it worked fine, then repeated on a Motion Mega LR and again it fails... I may have a problem with the flash ship on may Mega board.

Add this code in your setup function BEFORE your flash.initialize() call.


   word id = flash.readDeviceId();
   Serial.print("Flash ID="); Serial.println(id,HEX);


This will tell you what is being read back (if anything).

Tom
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: pedro.albuquerque on May 23, 2016, 04:13:23 PM
Thanks TomWs for your suggestion,

I tested it on Motion and the result was EF30, but on Motion Mega the answer is
"Start...Flash ID=0
Init FAIL!
"

Definitely the Flash has a problem....

Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: TomWS on May 23, 2016, 04:57:28 PM
Quote from: pedro.albuquerque on May 23, 2016, 04:13:23 PM
Thanks TomWs for your suggestion,

I tested it on Motion and the result was EF30, but on Motion Mega the answer is
"Start...Flash ID=0
Init FAIL!
"

Definitely the Flash has a problem....
The only other possibility (other than broken HW) is that your Arduino IDE has Board set for Moteino, not Moteino Mega...

Tom
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: pedro.albuquerque on May 23, 2016, 05:20:47 PM
Quote from: TomWS on May 23, 2016, 04:57:28 PM
Quote from: pedro.albuquerque on May 23, 2016, 04:13:23 PM
Thanks TomWs for your suggestion,

I tested it on Motion and the result was EF30, but on Motion Mega the answer is
"Start...Flash ID=0
Init FAIL!
"

Definitely the Flash has a problem....
The only other possibility (other than broken HW) is that your Arduino IDE has Board set for Moteino, not Moteino Mega...

Tom

I did check that, and even verified that it i using FLASH_SS = 23
"Start...Flash_ss:23
Flash ID=0
Init FAIL!
"
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: pedro.albuquerque on May 24, 2016, 05:41:33 AM
Problem Solved  :D :D :D Hurra!

The left pins (all 4) of the chip were left unsoldered, no contact.

No works fine, thank you for your help with confirmation and debugging clues.
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: Felix on May 24, 2016, 10:27:01 AM
Quote from: pedro.albuquerque on May 24, 2016, 05:41:33 AM
Problem Solved  :D :D :D Hurra!

The left pins (all 4) of the chip were left unsoldered, no contact.

No works fine, thank you for your help with confirmation and debugging clues.

Wow, this must have slipped through the cracks in testing.
I've only ever seen this happen when a resistor or other small part was dropped by the P&P under the chip, this happened once that I can remember.
I usually test the boards but it's a visual test that the chip can read back a value, so it's possible i missed it and if the chip was not soldered properly it ended up being a fail. Sorry about that and thanks for the update.
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: pedro.albuquerque on January 21, 2018, 04:49:30 PM
Hi Felix,

Since my last post on this issue, I have been working on the code aimed to this board.
Yes, it's true, it was "sleeping" for quite some time and since last 3 ou 4 week I have resumed the project.

This time I was experiencing execution freezing , but as I am also adding a touch display ILI9341, so I assumed it was my fault (bug).

I found execution is freezing every time I turn power ON (connect USB cable).
If I reset the board, than code will not fail.

This was particularly challenging to detect as for debugging I was using Serial.print to understand were it was stoping.
When I start the debug console (both using Platformio on ATOM, or Arduino IDE) the board is reset, so I could never see the problem while debug this way.

So I used a FTDI connected to pins 8 and 9, no power from the FTDI, and a battery to power the VIN and GND.

I ended up isolating the problem confirming what is happening is actually the code is not freezing, BUT, the SPIFlash is not working (no read and no Write) .

I reduced it to the very least/simpler code using  SPIFlash_ReadWrite example, and debug Serial.print message on SPIFlash library .

The SPI.initialize call is not able to collect the devideID

/// setup SPI, read device ID etc...
boolean SPIFlash::initialize()
{
    char c;
  #if defined (SPCR) && defined (SPSR)
    _SPCR = SPCR;
    _SPSR = SPSR;
  #endif
  pinMode(_slaveSelectPin, OUTPUT);
  Serial.println("[SPIF] SS pin set to OUTPUT!"); // DEBUG
    Serial.print("[SPIF] DevideID!");Serial.println(readDeviceId(),HEX); // DEBUG[/b][/b]
    //while(!Serial.available());
    //Serial.print(c=Serial.read());
#ifdef SPI_HAS_TRANSACTION
  _settings = SPISettings(4000000, MSBFIRST, SPI_MODE0);
#endif
    Serial.println("[SPIF] SPISetting OK!"); // DEBUG
    Serial.print("[SPIF] DevideID!");Serial.println(readDeviceId(),HEX); // DEBUG

  unselect();
  wakeup();

   Serial.print("[SPIF] DevideID!");Serial.println(readDeviceId(),HEX); // DEBUG
   

  if (_jedecID == 0 || readDeviceId() == _jedecID) {
    command(SPIFLASH_STATUSWRITE, true); // Write Status Register
    SPI.transfer(0);                     // Global Unprotect
    unselect();
    return true;
  }
  return false;
}


the debug console (arduinoIDE) is showing  (first with Power ON, and than with Reset pressed)

QuoteStart...[SPIF] SS pin set to OUTPUT!
[SPIF] DevideID!FFFF
[SPIF] SPISetting OK!
[SPIF] DevideID!FFFF
[SPIF] DevideID!FFFF
Init FAIL!
Start...[SPIF] SS pin set to OUTPUT!
[SPIF] DevideID!EF30
[SPIF] SPISetting OK!
[SPIF] DevideID!EF30
[SPIF] DevideID!EF30
Init OK!

Question: did you experience this before ?

My suspicion is that the Flash Memory is defective.

Not sure how to debug it further... Any idea ?

(I have even redone all sodering to make sure there is no bad contact still, but If that was the case I would not expect this behaviour) .

Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: perky on January 21, 2018, 06:25:11 PM
If the EEPROM itself is in sleep mode it won't respond correctly when probed. I think this has been covered before, try searching the forum for more.

Mark.
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: Felix on January 22, 2018, 09:44:18 AM
I think this thread and solution might be of interest:

https://lowpowerlab.com/forum/moteino/one-solution-to-moteino-failure-to-return-from-sleep/
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: pedro.albuquerque on February 12, 2018, 03:11:57 PM
Thank you Felix and perky,

In fact I still miss to understand what is going on.
i see in common with the thread you pointed me to that the code is sticked in the loop
  if (cmd != SPIFLASH_WAKE) while(busy());


of the command member of the SPIFlash library.
But the resemblance stops there as I am not putting my board to sleep in any moment.
I feel the problem as I power up the board, every time a power-up he board.

I even started to complicate by developing a state analyser from an ESP32 (but lets live that story aside for now  :) )

So, "as I cannot beat them I joined them", meaning, if a reset is solving my problem, I implemented a "smart" soft reset in my main code



#include <avr/wdt.h>
#define Reset_AVR() wdt_enable(WDTO_1S); while(1) {} // Soft reset Arduino using watchdog
.....


void setup(){

// initialize Serial port for debugging
Serial.begin(SERIAL_BAUD); //Initialize the Serial port at the specified baud rate
Serial.println F("GPS AND TELEMETRY MODULE");
Serial.println(VERSION);
Serial.println F("Initializing...");

Serial.print("Flash DeviceID:"); Serial.print(flash.readDeviceId());
if(flash.readDeviceId() != 0xEF30){
           Serial.print("Soft Reset");
           Reset_AVR();
         }
....


So this way, in case my Flash is not responding I just do a reset.
For now its working.

(but I am still not satisfied. I hate when I do not understand what is going on....)

thank for your inputs, I may try to investigate in the "Release power-up" direction as on post https://lowpowerlab.com/forum/moteino/one-solution-to-moteino-failure-to-return-from-sleep/msg21452/#msg21452
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: perky on February 12, 2018, 03:59:25 PM
The flash itself is asleep from power up, all commands are ignored except the wakeup command. Therefore you cannot read the device ID or get status from the flash.

Could you try adding the following line before trying to read the ID:


flash.wakeup();


Mark.
Title: Re: Listening at 433 Mhz... SPI Flash Init FAIL! (is chip present?) [SOLVED]
Post by: pedro.albuquerque on February 12, 2018, 05:11:36 PM
Hi Pearky,

thanks for such a quick reply.
Just tried you suggestion



void setup(){

// initialize Serial port for debugging
Serial.begin(SERIAL_BAUD); //Initialize the Serial port at the specified baud rate
Serial.println F("GPS AND TELEMETRY MODULE");
Serial.println(VERSION);
Serial.println F("Initializing...");
Serial.println F("flash.wakeup");
flash.wakeup();
Serial.print("Flash DeviceID:"); Serial.println(flash.readDeviceId(),HEX);
//if(flash.readDeviceId() != 0xEF30){
        //  Serial.print("Soft Reset");
        //  Reset_AVR();
        //}




as you can see just added it just before retrieving the deviceID, and commented out the Soft Reset, and the result was still that is stop in the While(busy()) loop

Quote
GPS AND TELEMETRY MODULE
GS LR MEGA V1.3.0
Initializing...
flash.wakeup

Flash DeviceID:FFFF
[FlashLOG] initialize

My previous line of investigation was to try to understand what AVR Soft reset actually does.
I analysed the behaviour of the main SPI pins, namely the MISO, MOSI, CS and CLK and I could not notice a diference in behaviour from a Power and a Hardware Reset.

I also tried to use a 10k Resistor to pullup the CS pin to Vcc to comply with manufacturer advice
"The /CS input must track the VCC supply level at power-up (see "Power-up Timing and Write inhibit threshold" and Figure 26). If needed, a pull-up resister on /CS can be used to accomplish this."


no sucess!