LowPowerLab / SPIFlash

Arduino library for read/write access to SPI flash memory chips
GNU General Public License v3.0
170 stars 89 forks source link

SPIFlash in a CH552 microcontroller #30

Closed jnthas closed 2 years ago

jnthas commented 2 years ago

Hello. I'm writing this issue with hope that you could give me some help or guidance. I've ported your library to work with CH552 microcontrollers, it was simple because your library is easy to use and well written. Source is here https://github.com/DeqingSun/ch55xduino/tree/ch55xduino/ch55xduino/ch55x/libraries/SPIFlash During my tests, I'm facing a strange behavior when I'm reading data. I'm using a W25Q32 (4MB) Let me explain step-by-step what happens, maybe you've already been through this. Any help is appreciated:

Notice there is a pattern in the readings, only the page 1,2,4,8 and 16 contains the byte I wrote.

//I'm reading the flash like this:
for (int j=0; j<16; j++) {    
  readBytes((j*256), _sbuffer, 255);

  for (uint8_t i=0; i<255; i++) {
    USBSerial_print(_sbuffer[i], HEX);
    USBSerial_print(".");    
  }  
}

OUTPUT:

Reading addr: 0 until 255
1) AA.AA.AA.AA.AA.AA.AA.AA.AA.AA. . (abbreviated for brevity reason) . .AA.AA.AA.AA.

Reading addr: 256 until 511
2) AA.AA.AA.AA.AA.AA.AA.AA.AA.AA. . . .AA.AA.AA.AA.

Reading addr: 512 until 767
3) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 768 until 1023
4) AA.AA.AA.AA.AA.AA.AA.AA.AA.AA. . . .AA.AA.AA.AA.

Reading addr: 1024 until 1279
5) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 1280 until 1535
6) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 1536 until 1791
7) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 1792 until 2047
8) AA.AA.AA.AA.AA.AA.AA.AA.AA.AA. . . .AA.AA.AA.AA.

Reading addr: 2048 until 2303
9) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 2304 until 2559
10) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 2560 until 2815
11) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 2816 until 3071
12) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 3072 until 3327
13) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 3328 until 3583
14) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 3584 until 3839
15) FF.FF.FF.FF.FF.FF.FF.FF.FF.FF. . . .FF.FF.FF.FF.

Reading addr: 3840 until 4095
16) AA.AA.AA.AA.AA.AA.AA.AA.AA.AA. . . .AA.AA.AA.AA.
LowPowerLab commented 2 years ago

Check your SPI settings and clocks and make sure everything is within the datasheet spec. Other than that I would use a logic analyzer to see the SPI bus traffic during these operations. Since this is not a demonstrated bug in the library, this issue will now be closed.