Electronic – Can’t seem to write to spi flash

flashpicspi

Well I've been stuck on this for a while, maybe 2-3 weeks at this point. I'm just not sure what I'm doing wrong. I'm trying to write to this spi flash part, and now I'm just running routines to erase, write, and read to try to isolate it but so far no luck. Of course I've solved a bunch a bugs along the way…

Anyway I've got my WP line tied high on the board, and I've slowed the clock way down to 200khz, then I run my erase routine and it looks like this:

enter image description here
First I check the ID just for debug, that's the 9F command, then I set WREN with 06 command, C7 is the whole chip-erase, and then I check the status bit with 05 and it's clear. This thing's chip erase time is only 35ms.

Now I reload my code and try a write:

enter image description here
First I set WREN with 06, check status to see that WREN is set with 05, it is, then send the page program command 02 to address 0x000000. You can see I'm writing deadcafe as the first few bits. Also not pictured here is after the write completes (one page or 256 bytes), I send the 0x04 command to disable WREN. I have observed that and I did set the last four bytes of my page buffer to be 0xAA, 0x55, 0xAA, 0x55 and I saw them just before the CS goes high.

Now stop reload code and try to run a read cycle:
enter image description here
Send 0x03 as the read command and 0x000000 as the address, and… all 0xFF back from the device.

I can see the device responding to my read ID and set WREN commands so I know it hears me, and can respond. I don't know what I'm doing wrong at this point. I guess I'll go back to reading the datasheet, and trying some things but if anyone has any insight I'd appreciate the help. It's shaping up to be another frustrating weekend working on this thing.

Best Answer

I just hate that this is still at the top of the 'unanswered' list, so I'm going to answer.

As stated in the comments by 'confused', there is a command called 'Global Unlock' that must be executed before writing to the flash part.