Go Down

Topic: SPI Flash chip not working as expected (Read 4921 times) previous topic - next topic

ematson5897

I salvaged a flash chip from a digital photo frame this morning. I found the datasheet and made a sketch that should write a binary 01010101 to address 1000000 on the chip, then read it and output it to the serial monitor. However, It always returns 0. No matter what I read, address, status register, anything, it always comes up with 0. I have verified my wiring. I have spi through voltage dividers to the chip, with vcc to 3.3v and vss to GND. The chip is decoupled. That only leaves my code.

Datasheet:
http://pdf1.alldatasheet.com/datasheet-pdf/view/207658/EON/EN25F80-100HCP.html

Code
Code: [Select]

// inslude the SPI library:
#include <SPI.h>


// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 20;
  long address1 = 1000000;
void setup() {
  Serial.begin(9600);
  SPI.setBitOrder(MSBFIRST);
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
    digitalWrite(slaveSelectPin,LOW);
    SPI.transfer(6);
    digitalWrite(slaveSelectPin,HIGH);
    Write(address1, B01010101);
}

void loop() {
     digitalWrite(slaveSelectPin,LOW);
//  send in the address and value via SPI:



Serial.println(Read(address1),BIN);


delay(10000);

}




void Write(long address, byte value){
     digitalWrite(slaveSelectPin,LOW);
//  send in the address and value via SPI:
  SPI.transfer(2);
  SPI.transfer((address) & B11111111);
  SPI.transfer((address >> 8) & B11111111);
  SPI.transfer((address >> 16) & B11111111);
  SPI.transfer(value);
//   take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);
}
byte Read(long address)
{
    byte value;
     digitalWrite(slaveSelectPin,LOW);
//  send in the address and value via SPI:
  SPI.transfer(3);
  SPI.transfer((address) & B11111111);
  SPI.transfer((address >> 8) & B11111111);
  SPI.transfer((address >> 16) & B11111111);
  value = SPI.transfer(0);
//   take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);
  return value;
}


Any help is appreciated,
ematson5897

ematson5897

Is this what is causing my problem? is the arduino doing this at the same time?
(from the datasheet)
Quote
In the case of a Page Program (PP), Sector Erase (SE), Block Erase (BE), Chip Erase (CE), Write Status
Register (WRSR), Write Enable (WREN), Write Disable (WRDI) or Deep Power-down (DP) instruction,
Chip Select (CS#) must be driven High exactly at a byte boundary, otherwise the instruction is rejected,
and is not executed. That is, Chip Select (CS#) must driven High when the number of clock pulses after
Chip Select (CS#) being driven Low is an exact multiple of eight. For Page Program, if at any time the
input byte is not a full byte, nothing will happen and WEL will not be reset.

ematson5897

I made code that reads the addresses and status register and prints them via serial. You can tell the results are gibberish because the status register byte should stay constant. Here is the data in this format: address  -_-  status register  -_-  Address byte value
Quote
0  -_-   0  -_-   0
1  -_-   0  -_-   0
2  -_-   0  -_-   0
3  -_-   0  -_-   0
4  -_-   0  -_-   0
5  -_-   11111111  -_-   11111111
6  -_-   11111111  -_-   11111111
7  -_-   11111111  -_-   11111111
8  -_-   11111111  -_-   11111111
9  -_-   11111111  -_-   0
10  -_-   0  -_-   0
11  -_-   0  -_-   0
12  -_-   0  -_-   0
13  -_-   0  -_-   0
14  -_-   0  -_-   0
15  -_-   0  -_-   0
16  -_-   0  -_-   0
17  -_-   0  -_-   0
18  -_-   0  -_-   0
19  -_-   0  -_-   0
20  -_-   0  -_-   0
21  -_-   0  -_-   0
22  -_-   11111111  -_-   11111111
23  -_-   11111111  -_-   11111111
24  -_-   11111111  -_-   11111111
25  -_-   11111111  -_-   11111111
26  -_-   11111111  -_-   0
27  -_-   0  -_-   0
28  -_-   0  -_-   0
29  -_-   0  -_-   0
30  -_-   0  -_-   0
31  -_-   0  -_-   0
32  -_-   0  -_-   0
33  -_-   0  -_-   0
34  -_-   0  -_-   0
35  -_-   0  -_-   0
36  -_-   0  -_-   0
37  -_-   0  -_-   0
38  -_-   11111111  -_-   11111111
39  -_-   11111111  -_-   11111111
40  -_-   11111111  -_-   11111111
41  -_-   11111111  -_-   11111111
42  -_-   11111111  -_-   0
43  -_-   0  -_-   0
44  -_-   0  -_-   0
45  -_-   0  -_-   0
46  -_-   0  -_-   0
47  -_-   0  -_-   0
48  -_-   0  -_-   0
49  -_-   0  -_-   0
50  -_-   0  -_-   0
51  -_-   0  -_-   0
52  -_-   0  -_-   0
53  -_-   0  -_-   0
54  -_-   0  -_-   0
55  -_-   11111111  -_-   11111111
56  -_-   11111111  -_-   11111111
57  -_-   11111111  -_-   11111111
58  -_-   11111111  -_-   11111111
59  -_-   11111111  -_-   0
60  -_-   0  -_-   0
61  -_-   0  -_-   0
62  -_-   0  -_-   0
63  -_-   0  -_-   0
64  -_-   0  -_-   0
65  -_-   0  -_-   0
66  -_-   0  -_-   0
67  -_-   0  -_-   0
68  -_-   0  -_-   0
69  -_-   0  -_-   0
70  -_-   0  -_-   0
71  -_-   0  -_-   0
72  -_-   11111111  -_-   11111111
73  -_-   11111111  -_-   11111111
74  -_-   11111111  -_-   11111111
75  -_-   11111111  -_-   11111111
76  -_-   11111111  -_-   0
77  -_-   0  -_-   0
78  -_-   0  -_-   0
79  -_-   0  -_-   0
80  -_-   0  -_-   0
81  -_-   0  -_-   0
82  -_-   0  -_-   0
83  -_-   0  -_-   0
84  -_-   0  -_-   0
85  -_-   0  -_-   0
86  -_-   0  -_-   0
87  -_-   0  -_-   0
88  -_-   0  -_-   11111111
89  -_-   11111111  -_-   11111111
90  -_-   11111111  -_-   11111111
91  -_-   11111111  -_-   11111111
92  -_-   11111111  -_-   11111111
93  -_-   0  -_-   0
94  -_-   0  -_-   0
95  -_-   0  -_-   0
96  -_-   0  -_-   0
97  -_-   0  -_-   0
98  -_-   0  -_-   0
99  -_-   0  -_-   0
100  -_-   0  -_-   0
101  -_-   0  -_-   0
102  -_-   0  -_-   0
103  -_-   0  -_-   0
104  -_-   11111111  -_-   11111111
105  -_-   11111111  -_-   11111111
106  -_-   11111111  -_-   11111111
107  -_-   11111111  -_-   11111111
108  -_-   11111111  -_-   0
109  -_-   0  -_-   0
110  -_-   0  -_-   0
111  -_-   0  -_-   0
112  -_-   0  -_-   0
113  -_-   0  -_-   0
114  -_-   0  -_-   0
115  -_-   0  -_-   0
116  -_-   0  -_-   0
117  -_-   0  -_-   0
118  -_-   0  -_-   0
119  -_-   0  -_-   0
120  -_-   11111111  -_-   11111111
121  -_-   11111111  -_-   11111111
122  -_-   11111111  -_-   11111111
123  -_-   11111111  -_-   11111111
124  -_-   0  -_-   0
125  -_-   0  -_-   0
126  -_-   0  -_-   0
127  -_-   0  -_-   0
128  -_-   0  -_-   0
129  -_-   0  -_-   0
130  -_-   0  -_-   0
131  -_-   0  -_-   0
132  -_-   0  -_-   0
133  -_-   0  -_-   0
134  -_-   0  -_-   0
135  -_-   0  -_-   0
136  -_-   11111111  -_-   11111111
137  -_-   11111111  -_-   11111111
138  -_-   11111111  -_-   11111111
139  -_-   11111111  -_-   11111111
140  -_-   0  -_-   0
141  -_-   0  -_-   0
142  -_-   0  -_-   0
143  -_-   0  -_-   0
144  -_-   0  -_-   0
145  -_-   0  -_-   0
146  -_-   0  -_-   0
147  -_-   0  -_-   0
148  -_-   0  -_-   0
149  -_-   0  -_-   0
150  -_-   0  -_-   0
151  -_-   0  -_-   11111111
152  -_-   11111111  -_-   11111111
153  -_-   11111111  -_-   11111111
154  -_-   11111111  -_-   11111111
155  -_-   11111111  -_-   0
156  -_-   0  -_-   0
157  -_-   0  -_-   0
158  -_-   0  -_-   0
159  -_-   0  -_-   0
160  -_-   0  -_-   0
161  -_-   0  -_-   0
162  -_-   0  -_-   0
163  -_-   0  -_-   0
164  -_-   0  -_-   0
165  -_-   0  -_-   0
166  -_-   0  -_-   0
167  -_-   0  -_-   11111111
168  -_-   11111111  -_-   11111111
169  -_-   11111111  -_-   11111111
170  -_-   11111111  -_-   11111111
171  -_-   11111111  -_-   0
172  -_-   0  -_-   0
173  -_-   0  -_-   0
174  -_-   0  -_-   0
175  -_-   0  -_-   0
176  -_-   0  -_-   0
177  -_-   0  -_-   0
178  -_-   0  -_-   0
179  -_-   0  -_-   0
180  -_-   0  -_-   0
181  -_-   0  -_-   0
182  -_-   0  -_-   0
183  -_-   11111111  -_-   11111111
184  -_-   11111111  -_-   11111111
185  -_-   11111111  -_-   11111111
186  -_-   11111111  -_-   11111111
187  -_-   0  -_-   0
188  -_-   0  -_-   0
189  -_-   0  -_-   0
190  -_-   0  -_-   0
191  -_-   0  -_-   0
192  -_-   0  -_-   0
193  -_-   0  -_-   0
194  -_-   0  -_-   0
195  -_-   0  -_-   0
196  -_-   0  -_-   0
197  -_-   0  -_-   0
198  -_-   0  -_-   11111111
199  -_-   11111111  -_-   11111111
200  -_-   11111111  -_-   11111111
201  -_-   11111111  -_-   11111111
202  -_-   11111111  -_-   0
203  -_-   0  -_-   0
204  -_-   0  -_-   0
205  -_-   0  -_-   0
206  -_-   0  -_-   0
207  -_-   0  -_-   0
208  -_-   0  -_-   0
209  -_-   0  -_-   0
210  -_-   0  -_-   0
211  -_-   0  -_-   0
212  -_-   0  -_-   0
213  -_-   0  -_-   0
214  -_-   0  -_-   0
215  -_-   11111111  -_-   11111111
216  -_-   11111111  -_-   11111111
217  -_-   11111111  -_-   11111111
218  -_-   11111111  -_-   11111111
219  -_-   0  -_-   0
220  -_-   0  -_-   0
221  -_-   0  -_-   0
222  -_-   0  -_-   0
223  -_-   0  -_-   0
224  -_-   0  -_-   0
225  -_-   0  -_-   0
226  -_-   0  -_-   0
227  -_-   0  -_-   0
228  -_-   0  -_-   0
229  -_-   0  -_-   0
230  -_-   11111111  -_-   11111111
231  -_-   11111111  -_-   11111111

Here is my code
Code: [Select]


#include <SPI.h>
byte writeEnable = 6;





const int slaveSelectPin = 20;




  long address1 = 0000000;
 
 
 
void setup()
{
 
  Serial.begin(9600);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV128);
   SPI.setDataMode(0);
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  digitalWrite(slaveSelectPin,HIGH);
  // initialize SPI:
  SPI.begin();
 
    digitalWrite(slaveSelectPin,LOW);
    SPI.transfer(writeEnable);
    digitalWrite(slaveSelectPin,HIGH);
    delay(1000);
    Write(address1, B01010101);
    delay(1000);
   
}

void loop() {
   
//  send in the address and value via SPI:


for(long a=0; a<1000000; a++){
Serial.print(a);
Serial.print("  -_-   ");
Serial.print(ReadSR(),BIN);
Serial.print("  -_-   ");
Serial.println(Read(a),BIN);


delay(50);
}
}




void Write(long address, byte value){
     digitalWrite(slaveSelectPin,LOW);
//  send in the address and value via SPI:
  SPI.transfer(2);
  SPI.transfer((address >> 16) & B11111111);
  SPI.transfer((address >> 8) & B11111111);
  SPI.transfer((address) & B11111111);
  SPI.transfer(value);
//   take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);
}
byte Read(long address)
{
    byte value;
     digitalWrite(slaveSelectPin,LOW);
//  send in the address and value via SPI:
  SPI.transfer(3);
  SPI.transfer((address >> 16) & B11111111);
  SPI.transfer((address >> 8) & B11111111);
  SPI.transfer((address) & B11111111);
  value = SPI.transfer(0);
//   take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);
  return value;
}
byte ReadSR()
{

     digitalWrite(slaveSelectPin,LOW);
//  send in the address and value via SPI:
  SPI.transfer(5);
  byte value = SPI.transfer(0);
//   take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);
  return value;
}

CrossRoads

I believe you need to declare D10, the SS pin associated with the internal SPI hardware, as an output also, otherwise I think the chip may think it is an SPI slave, vs being the master. You can still use this for chip select.

const int slaveSelectPin = 20;

You are using a Mega? There is no 20 on an Uno. I think SS on the Mega is 50, but confirm that.
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.

ematson5897

I am using the teensy++ so I think I am using the correct pin. Here is the pin info http://www.pjrc.com/teensy/pinout.html

ematson5897

Forgot to mention that output B0 the ss pin corresponds to pin 20 in arduino software

ematson5897

And a logic probe connected to the data out pin doesn't return anything, but all other pins are pulsing as usual

ematson5897

#7
Jun 15, 2012, 07:58 pm Last Edit: Jun 15, 2012, 08:01 pm by ematson5897 Reason: 1
Wait i have data. I connected the hold pin to 3.3v. It was floating before. I'll check it to see if it is constant


EDIT
The data has been the same the last 3 runs, so I am going to erase it and try to write

ematson5897


ematson5897

#9
Jun 17, 2012, 12:09 am Last Edit: Jun 17, 2012, 05:31 am by ematson5897 Reason: 1
Heres what I have so far:
(keep in mind that all of the commands that don't work rely on write enable to be executed first, so that could be the only problem)

Commands that work:
Write enable
Write
Read
Read status register
Fast read
Enter/exit deep power down
Write Status Register
Chip Erase
Sector/block erase

Commands that I haven't tried yet:
Read manufacturer/device ID
Read ID
Enter OTP mode


I will update this as I go. Once I get everything, I will release a library if asked

**Edit1**
Fast read works
I believe the deep power down stuff works, but I'm not quite sure

**Edit2**
Verified that deep power down stuff works
Block and sector erase dont work

**EDIT3**
Finally got write enable and write, haven't tried erases yet

**EDIT4**
Erases now work. Probably going to skip ID stuff and OTP for now. Write status register should work, not tested yet.
And forgot to mention, this all started to work after a power cycle on the chip

ematson5897

#10
Jun 17, 2012, 11:41 pm Last Edit: Jun 18, 2012, 04:42 am by ematson5897 Reason: 1
Aparrenty chips like this are everywhere. I found a pcb from a cd drive and it had a chip that was the exact same except it had twice the flash and supports quad spi. Can I utilize quad spi with arduino?

Datasheet is here
http://www.winbond.com.tw/hq/enu/ProductAndSales/ProductLines/FlashMemory/SerialFlash/W25Q16V.htm

ematson5897

And the chip I mentioned above refuses to be written to. I can chip erase but not write. Don't know whats wrong with it

Go Up