ported for ff-lpc546xx
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 #include "AT45.h" 00004 00005 /* Tested on L-Tek FF_LPC546xx */ 00006 00007 #define PIN_MOSI P0_8 00008 #define PIN_MISO P0_9 00009 #define PIN_SCK P0_6 00010 #define PIN_CS P0_7 00011 00012 00013 DigitalOut led1(LED1); 00014 00015 SPI spi(PIN_MOSI, PIN_MISO, PIN_SCK); // mosi, miso, sclk 00016 AT45 spif(&spi, PIN_CS); 00017 00018 DigitalOut myled(LED1); 00019 00020 int main() { 00021 00022 printf("spif test\n\r"); 00023 00024 00025 printf("id: %d\n\r", spif.id()); 00026 00027 printf("spif size: %d bytes\n\r", spif.device_size()); 00028 printf("spif page erase size: %d bytes\n\r", spif.pagesize()); 00029 printf("spif pages: %d\n\r", spif.pages()); 00030 printf("spif block erase size: 4096 bytes\n\r"); 00031 printf("spif blocks: %d\n\r", spif.blocks()); 00032 printf("id: %d\n\r", spif.id()); 00033 00034 int pagesize = spif.pagesize(); 00035 00036 // Write "Hello World!" to a block 00037 char *buffer = (char*) malloc(pagesize); 00038 sprintf(buffer, "Hello World!\n"); 00039 spif.page_erase(3); 00040 spif.write_page(buffer, 3); 00041 00042 char *buffer2 = (char*) malloc(pagesize); 00043 // Read back what was stored 00044 spif.read_page(buffer2, 3); 00045 00046 printf("%s", buffer2); 00047 00048 while(1) { 00049 myled = 1; 00050 wait(0.2); 00051 myled = 0; 00052 wait(0.2); 00053 00054 } 00055 }
Generated on Wed Jul 20 2022 06:18:06 by
1.7.2