SPI DataFlash
Source code can be downloaded from source:/Examples/SPI_DataFlash
Description
Testing (write/read) flash memory.
From the main.c source file:
Initialization
1 SystemInit();
2 CGU_Init();
3
4 AT45_Init();
Prepare buffer
1 for (i = 0; i < sizeof(writeBuffer); i++)
2 {
3 writeBuffer[i] = i;
4 }
Write page
1 AT45_ErasePage(baseaddr);
2 AT45_WritePage(baseaddr, writeBuffer, sizeof(writeBuffer));
Execution
1 while (1)
2 {
3 // Clear read buffer
4 for (i = 0; i < sizeof(writeBuffer); i++)
5 {
6 readBuffer[i] = ~writeBuffer[i];
7 }
8
9 // Read data back
10 AT45_ReadPage(baseaddr, readBuffer, sizeof(readBuffer));
11
12 // Verify
13 for (i = 0; i < sizeof(writeBuffer); i++)
14 {
15 if ( writeBuffer[i] != readBuffer[i])
16 {
17 while (1); // catch th error
18 }
19 }
20 }