0
\$\begingroup\$

I am new to SPI flash memory reading and/or writing. As I was fiddling with it, I see that I cannot write to the first 32 bytes of the device GD25Q128C. It always reads back something that I have not written.

I have checked online and think that it could be due the first 32 bytes of every page is used for some other purpose?

I can successfully write and read from the remaining addresses.

Can somebody give more information on this?

Update:

It is the wikipedia that hints my assumptionenter image description here

Following image shows the logic analyzer capture for writing to first 32 bytes: enter image description here

Following image shows the logic analyzer capture for writing after first 32 bytes: enter image description here

\$\endgroup\$
12
  • \$\begingroup\$ Babu James - Hi, (a) You said that you have: "[...] checked online and think that it could be due the first 32 bytes of every page is used for some other purpose". Please can you edit the question and add a link to that website claim - I haven't heard of that before. (b) Have you validated the actual SPI signals when running your code, to ensure that what you think is being sent & received on the SPI bus, is actually what is being sent & received? A small logic analyser would be ideal for that. Can you add that trace into the question? Thanks. \$\endgroup\$
    – SamGibson
    Dec 7, 2020 at 10:24
  • 1
    \$\begingroup\$ Babu James - Thanks for adding that. I don't have time to review the SPI traces yet, - someone else might be quicker than me. I did wonder if you were assuming something like that part of the Wikipedia article applied to your SPI flash - it doesn't apply. (Even if a flash device does have extra bytes per page, typical for NAND flash, those bytes are normal and can be read/written just like the others - they are just used differently by the flash controller to store ECC bytes usually, but can be used to store anything). Your problem is elsewhere. \$\endgroup\$
    – SamGibson
    Dec 7, 2020 at 11:29
  • 1
    \$\begingroup\$ Well did you erase the page/sector/block first? Perhaps it still contains what your code has written earlier during your tests? \$\endgroup\$
    – Justme
    Dec 7, 2020 at 13:10
  • 1
    \$\begingroup\$ Why are your write and read commands different lengths depending on the address you're accessing? When you write to address 0 you're sending 02 00 00 (3 bytes) followed by 10 bytes of data (00 ... 09), while when you write to address 20 you're sending 02 00 00 20 (4 bytes) followed by the same 10 bytes data. \$\endgroup\$
    – brhans
    Dec 7, 2020 at 13:16
  • 1
    \$\begingroup\$ Have you erased the flash? Please note that it is flash memory, so you can only write bits to 0, and you cannot write bits to 1 unless you do an erase to make them 1. Now, have you tried erasing or not? \$\endgroup\$
    – Justme
    Dec 7, 2020 at 14:57

1 Answer 1

3
\$\begingroup\$

The writing works fine, but you seem to expect to get back what you write without erasing previous content. With Flash memory bits can only written to 0, not back to 1.

There must be some previous writes that have written bits to zero, so that is why reading back differs from data just written.

Flash chip blocks need to be erased to set bits back to 1, so they can then be written to 0.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.