Issue with SPI.h, teensy 3.6 arduino

Status
Not open for further replies.

Frillo

New member
Hello all,

I'm aiming to do some endurance testing of spi nor flash chips, and thought the teensy 3.6 would be a great microcontroller for the job.

For now I'm using the code from this instructables post:
http://www.instructables.com/id/How-to-Design-with-Discrete-SPI-Flash-Memory/
direct code link:
https://cdn.instructables.com/ORIG/F18/CHIA/I0C8YA8Z/F18CHIAI0C8YA8Z.cpp

The ic I have is a M25PE16 which shares the same instructions as the winbond ic from the instructables post.

I am able to get the flash to reply with its correct id, but more than half the time, the replies are all ones, and sometimes all zeros.
I have tried 10k ohms and 100k ohms pullups on the CS, but they just lock the signal to the rail?
MOSI seems to be always high when the spi isn't doing anything, and the SCK is always running (not sure if this is normal or not).

The problem might be with the flash ic, but for now I choose to believe the problem is with the teensy. I've tried 2 chips of the same kind, and the exact same behavior was observed.

Just for reference the pins used by SPI.h are:
CS0 - 10
MOSI0 - 11
MISO0 - 12
SCK0 -13


Should I be using a different header directory?
 
Hello all,

I'm aiming to do some endurance testing of spi nor flash chips, and thought the teensy 3.6 would be a great microcontroller for the job.

For now I'm using the code from this instructables post:
http://www.instructables.com/id/How-to-Design-with-Discrete-SPI-Flash-Memory/
direct code link:
https://cdn.instructables.com/ORIG/F18/CHIA/I0C8YA8Z/F18CHIAI0C8YA8Z.cpp

The ic I have is a M25PE16 which shares the same instructions as the winbond ic from the instructables post.

I am able to get the flash to reply with its correct id, but more than half the time, the replies are all ones, and sometimes all zeros.
I have tried 10k ohms and 100k ohms pullups on the CS, but they just lock the signal to the rail?
MOSI seems to be always high when the spi isn't doing anything, and the SCK is always running (not sure if this is normal or not).

The problem might be with the flash ic, but for now I choose to believe the problem is with the teensy. I've tried 2 chips of the same kind, and the exact same behavior was observed.

Just for reference the pins used by SPI.h are:
CS0 - 10
MOSI0 - 11
MISO0 - 12
SCK0 -13


Should I be using a different header directory?
Most of the time issues like this are just speed issues. Teensy is much faster than avr. Try to run the Teensy with 24Mhz. If this works, you may want to insert some delays before cs=0 line and set a low spi speed.

Isn't the endurance mentioned in the datasheet?
 
Last edited:
The endurance in the datasheet is just a "worst case" as far as I know, the real endurance with 100% wear leveling should be better. Or at least I need to prove what it is from actual testing, to be able to compare that value, to the endurance when using a ffs with not optimal wear leveling.

The flash ic is rated at 50MHz spi, so 48 should work. But it doesn't, and it's the same story when using 24. Is there any special trick to selecting the clock, or do I just select it in the arduino ide (what I've done so far).
 
Just found out there might be a conflict with the SPI.h of teensyduino and the one that comes with the arduino ide install. It seems the latter is the one selected when I look in the library manager, but I can't seem to be able to remove it? Any ideas? I've deleted the folder containing it but no luck.
 
The endurance in the datasheet is just a "worst case" as far as I know, the real endurance with 100% wear leveling should be better. Or at least I need to prove what it is from actual testing, to be able to compare that value, to the endurance when using a ffs with not optimal wear leveling.

The flash ic is rated at 50MHz spi, so 48 should work. But it doesn't, and it's the same story when using 24. Is there any special trick to selecting the clock, or do I just select it in the arduino ide (what I've done so far).

Yes, the SPI clock isn't eqal to the CPU clock (not even on the simple Arduinos), and you should use transactions (https://www.pjrc.com/teensy/td_libs_SPI.html).
But ok it's unlikely that this is the reason. Have you tried the delays ?
If yes, there must be a difference between the chips. I fear you have to compare & study the datasheets more detailed. I spent a lot of time with SPI Flash chips and can tell you,that there can be subtle differences that are important to know and software will not work without doing it _exactly_ right. They all have (almost) the same commands but the usage can be slightly different. For example, some want a write-enable before *every* write, for others it is sufficiant to do it once after power-on.

Edit: First, I'd try to read the status and id-bytes correctly. And double-check the connections (including pins like "hold" or "write-enable").

You know the Teensy already has a flash filesystem library ("SerialFlash") ?
 
Last edited:
It is not needed to remove it - please post your compiler-output.
You're not the first one who uses SPI or SPI-Flash on Teensy. There are tenthousands of other users (like me..)
 
This code appears to be missing pinMode(SS, OUTPUT);

It only works by mistake on AVR, because writing to a pin in it's default input state turns the pullup resistor on/off. So on AVR, this code isn't actually directly driving the SS pin as an output, but rather it's using the weak internal pullup resistor.

On Teensy 3.x, the pin default to a low power disable mode, not input mode. You must use pinMode to configure the pin.
 
This code appears to be missing pinMode(SS, OUTPUT);

It only works by mistake on AVR, because writing to a pin in it's default input state turns the pullup resistor on/off. So on AVR, this code isn't actually directly driving the SS pin as an output, but rather it's using the weak internal pullup resistor.

On Teensy 3.x, the pin default to a low power disable mode, not input mode. You must use pinMode to configure the pin.


That worked, thanks for the help :)

I am however only able to get it working with 180MHz set in arduino
 
Status
Not open for further replies.
Back
Top