Go Down

Topic: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :) (Read 74843 times) previous topic - next topic

wsteelmanj

I'm having a slight problem getting my chip to work. I have an Arduino Nano ATMega328p board and an SPI chip (W25Q256FV) wired to the board according to this schematic posted by Okio



Since my board runs on 5V I have several voltage dividers for the pins. Anyways when I run the SPI TestFlash.ino or Diangostics.ino it just says "Initialising Flash memory.........." and never gets past the flash.begin(). Thanks!

(Also Marzogh, thanks for all your work in building this library!)

CrossRoads

Post your code please. Use the code tag button </>, or Reply and Attach it (selected under the Reply box) if the code exceeds the forum character limit.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Marzogh

#77
Nov 16, 2016, 11:46 pm Last Edit: Nov 16, 2016, 11:59 pm by Marzogh Reason: Updated information
Hi wsteelmanj,

That's unfortunate. Which version of the library are you using? Also, could you uncomment the #define RUNDIAGNOSTIC in SPIFlash.cpp and find the _chipID(void) function in SPIFlash.cpp and uncomment the Serial.print lines as shown below.

Code: [Select]
bool SPIFlash::_chipID(void) {
//Get Manfucturer/Device ID so the library can identify the chip
    uint8_t manID, capID, devID ;
    //_getManId(&manID, &devID);
    _getJedecId(&manID, &capID, &devID);

    Serial.println(manID, HEX);
    Serial.println(capID, HEX);
    Serial.println(devID, HEX);

    if (manID != WINBOND_MANID && manID != MICROCHIP_MANID){ //If the chip is not a Winbond Chip
      errorcode = UNKNOWNCHIP; //Error code for unidentified chip
    #ifdef RUNDIAGNOSTIC
    _troubleshoot();
    #endif
    while(1);
    }


Save the modified file, re-compile and upload Diagnostics.ino and could you then post the Serial output here?

wsteelmanj

I'm using SPIFlash-2.4.0 (Sorry I meant to put that in my first post..)

and here's the output after changing the edited serial lines:

Code: [Select]
Initialising Flash memory..........
0
0
0
Error code: 0x02


Thanks!

Marzogh

Well, the chip isn't responding at all. The three zeros should be - in your case - 0xEF, 0x40, 0x19 respectively. Which is what the chip should return to the library when flash.begin() runs. This is why the Error code 0x02 - meaning 'Unknown Chip' - is returned.

Could you check your wiring please? And post a couple of photos of how it is wired up? I suspect it might be a dud chip, but no harm in checking the wiring  :) (Something similar happened to Stephan_Duino here --> link and it turned out to be a bad chip.)

wsteelmanj

#80
Nov 18, 2016, 04:42 am Last Edit: Nov 18, 2016, 04:48 am by wsteelmanj
I checked the wiring and tried it again with a new chip and it still didn't work.

Here are the wiring pics. You can ignore all the wires on the left (they're for several encoders and a LCD). Also I'm using a surface mounted SPI chip so the chip is on an adapter. The top row of the adapter pins are pins 8 to 5 (left to right) from the SPI chip and the bottom row is pins 1 to 4.





Sorry I know it's a sloppy board. I will also attach the excel file I used to plan it out before soldering which will hopefully help you find my error. I already tested all the voltage dividers with a simple program that set the data pins at 5V and they were outputting 2.8V which is sufficient for the SPI chip. Thanks!

Marzogh

#81
Nov 18, 2016, 11:40 pm Last Edit: Nov 19, 2016, 04:31 am by Marzogh
Ah. Good old voltage dividers. They can cause some serious performance issues.

All signals have capacitance, partly from the IC pins and partly from the wires/PCB traces connecting the devices. When you throw a resistor into the mix, you are creating an RC filter which smooths out the sharp edges in your signals - especially hurting the clock pulse.

Now, this is usually ok if the resistance is small enough. I have, in a pinch, thrown in a <150 Ohm total resistance to create a voltage divider. Anything higher than that degrades the signal quality too much. Also, voltage divider resultant signal degradation will not affect your MISO, MOSI and CS lines as much as the CLK line. Any clock pulse needs a clean sharp digital transition between low and high. I'd recommend throwing in a Voltage Level converter from Sparkfun or Adafruit. They're cheap and high quality - I've never had issues with them degrading SPI signals.

wsteelmanj

So if I use a smaller resistance for my clock voltage divider it should work? Or do I need to reduce the resistances for the other pins as well? I'll try reducing the clock resistance first and let you know how it goes! Thanks!

Marzogh

It might work. For clock signals I'd personally recommend against voltage dividers and recommend the use of a proper level shifting set up. However, if you've got an oscilloscope, you should be able to see the high to low transitions clearly and that should help with picking the right resistors to use.

Marzogh

For those of you that have managed to get your hands on ESP32 dev boards, I've got v2.6.0-w.i.p currently working with the ESP32 core (as it stands at commit 67fd652). :D

Also, for some unknown reason, SPI clock speeds higher than (board speed)/4 are not stable and so, the clock speed for ESP32 dev boards has currently been throttled to 20MHz (I'm testing with the Sparkfun ESP32 Thing - it has a max speed of 80MHz) - if you have any issues, check your board's speed first and change the SPICLK define in defines.h to your (board clock speed)/4.

wsteelmanj

#85
Nov 30, 2016, 09:48 pm Last Edit: Nov 30, 2016, 10:10 pm by wsteelmanj
So I finally got back in the lab after thanksgiving to check out the clock pulse on an o-scope and there is nothing coming off of pin 13 (SCK)... Do I have to add some code to output the clock pulse on this pin or is my arduino just dead or something?

Also I got an 8MHz signal on pin 9 using the instructions from here:
http://arduino.stackexchange.com/questions/16698/arduino-constant-clock-output

If I can't get pin 13 working can I just put my voltage divider on pin 9 and use it to drive the chip? Thanks!

CrossRoads

SCK would only be active for 8 clocks during an SPI.transfer().
Not continuously.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Marzogh

The SCK pulse is started/ended by the library as needed, during an SPI transaction. I'd recommend that you try connecting another SPI based sensor (a 3.3V one, to be specific) to your board and see if it works. That should tell you if you have a busted chip.

Also as CrossRoads said, an SCK does not constantly pulse at 8MHz. This is what a typical SPI signal would look like --> SPI Signal on Logic Analyzer (Image linked directly from Nick Gammon's post on SPI)

I've tested a similar setup with my Arduino Nano & a Winbond W25Q128FV (I don't have a W25Q256FV, but the difference is only the amount of storage) and it works fine with v 2.5.0 - however, I always use a logic level converter in situations like this - this one to be precise

Marzogh

#88
Apr 16, 2017, 07:06 pm Last Edit: Apr 16, 2017, 07:20 pm by Marzogh
Just pushed through an update to v2.6.0. This update squashes one major bug, adds support forthe ESP32 and other boards, loses a superfluous function and has a large number of optimizations for speed, stability & ease of development.

Bugs Squashed
- Fixed issue with reading status register 2 and the Suspend operation where the library was not checking the suspend status correctly.

Deletions
- flash.getChipName() has been removed as it is superfluous now that the library is now on its way to multi-chip compatibility.
- The library is not compatible with the ATTiny85 anymore. Currently working on a fix which will hopefully be rolled out in v2.7.0

New Boards supported
- RTL8195A compatibility tested and enabled by @boseji on 02.03.17. Code modified to fit with the library structure by Prajwal Bhattaram on 14.04.17.
- Now supports the ESP32 core for Arduino as of the current commit 7d0968c on 16.04.2017. The ESP32 core currently does not support analogRead and so randomSeed(AnalogRead(A0)) cannot be used. Also, for some unknown reason, SPI clock speeds higher than board speed/4 are not stable and so, the clock speed for ESP32 dev boards has currently been throttled to 20MHz.
- Added support for the Simblee module.

Enhancements & Optimizations
- flash.error() now takes an optional argument 'VERBOSE'. By default the verbosity argument  is set to false and calling flash.error() still returns the latest error code as an unsigned byte. However, running flash.error(VERBOSE) will not only return the latest error code, but will also print it to serial. This - especially in boards with resources to spare - will result in a detailed error report printed to serial.
- flash.begin() now returns a boolean value to indicate establishment of successful comms with the flash chip. Usercode can be made more efficient now by calling
Code: [Select]

if (!flash.begin()) {
      Serial.println(flash.error(VERBOSE));
}

 to identify a problem as soon as the library code is run.
- The internal _addressCheck() function now locks up usercode with appropriate error codes if
  • flash.begin() has not been called (or)
  • There is a possible issue with the wiring - i.e. the flash chip is non-responsive (or)
  • If the chip's capacity either cannot be identified & the user has not defined a chipSize in flash.begin().

- Fixed powerDown() to be more efficient. The chip now powers down much faster than before.
- Added a new error code. Library can now detect non-responsive chips - bad wiring or otherwise.
- Streamlined variables to make code structure better.
- Changed library structure to enable the addition of multi-flash compatibility in the near future.
- moved `#define RUNDIAGNOSTIC` & `#define HIGHSPEED` to SPIFlash.h from SPIFlash.cpp.
- Now works with other Winbond modules (not in the official supported module list) (beta) by taking the flash memory size in bits as an argument in `flash.begin(_chipSize);`
- Formatted code to be better human readable.
- Changed the internal `_troubleshoot()` function to use fewer resources.

As always, you can find this version on Github here --> SPIFlash Library for Arduino v2.6.0
A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the libary to v2.6.0 :)

miduchp

Hi Marzogh

I've recenetly got back to your SPI Library. I've been using it previously on version 2.3.1 with chip Winbond 25q40bvnig.

After update to version 2.6.0 it throws random errors on diagnostics. Errors are showing up since version 2.4.0

It looks like this:


Initialising Flash memory..........


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                   SPIFlash Library version: 2.6.0
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                               Get ID
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JEDEC ID: ef4013h
Manufacturer ID: efh
Memory Type: 40h
Capacity: 524288 bytes
Maximum pages: 2048
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                              Data Check
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Data Written || Data Read || Result || Write Time || Read Time || Write Time || Fast Read Time
|| || || || || (No Error Chk) ||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
35 || 35 || Pass || 52 us || 48 us || 52 us || 64 us
-110 || -110 || Pass || 52 us || 48 us || 52 us || 48 us
4520 || 4520 || Pass || 64 us || 60 us || 64 us || 56 us
-1250 || -1250 || Pass || 64 us || 56 us || 64 us || 56 us
876532 || 4294967075 || Fail || 64 us || 60 us || 68 us || 60 us
-10959 || -221 || Fail || 64 us || 60 us || 68 us || 68 us
3.14 || 3.14 || Pass ⸮⸮

Read values are completely random. Number of pass / fail tests are also completely random.

Did you dropped support for this particular chip ? Wiring is rather ok.

Go Up