Electronic – SPI Flash: Half the bits are zero

flashspistm32

I have an STM32 driving two very similar SPI Flashes, an N25Q and an M25P.

Strangely, while my driver copes with the N25Q perfectly well, the M25P is only "half" working. What happens is that when I write a page of bytes, and read that page back, the four MSB bits of each byte is 0, and the four LSB bits of each byte is correct.

What could be causing half the bits to be 0?

Best Answer

Did you erase the affected memory pages first? For flash memory, you can change only 1's to 0's (the M25P data sheet from above states this explicitly on page 22, in the N25Q its on page 12). So if the M25P was filled with 0x0f's before, you would get exactly that result. When you use the same write command (0x02) for both, you should be fine. Using dual or quad mode would result in in 2 (or 4) bits wrong, but not half a byte. Since I suppose you program a whole page, I think this can't be stuck address bits. Other sources for the problem might be: missing blocking capacitor for the flash IC, or wrong SPI mode (which can cause strange results since then normally you read data exactly the moment it is changing). The latter one can be checked with a logic analyzer or a scope.