Suga koubou
/
SPIRAM_23LC1024
SPI RAM 23LC1024 (Microchip) 1Mbit see: http://mbed.org/users/okini3939/notebook/extend-memory/
Revision 1:a7b1803dfa44, committed 2012-11-09
- Comitter:
- okini3939
- Date:
- Fri Nov 09 06:23:54 2012 +0000
- Parent:
- 0:c5ba7d914282
- Commit message:
- fix
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c5ba7d914282 -r a7b1803dfa44 main.cpp --- a/main.cpp Fri Nov 09 00:32:20 2012 +0000 +++ b/main.cpp Fri Nov 09 06:23:54 2012 +0000 @@ -1,5 +1,6 @@ /* * SPI RAM 23LC1024 (Microchip) + * 1Mbit */ #include "mbed.h" @@ -12,7 +13,7 @@ Serial pc(USBTX, USBRX); SPI spi(p11, p12, p13); // mosi, miso, sclk -DigitalOut cs(p17); +DigitalOut cs(p17), hold(p18); int ram_write (int addr, char *buf, int len) { int i; @@ -49,9 +50,12 @@ int main() { int i; char buf[256]; + Timer t; cs = 1; + hold = 1; pc.baud(115200); + spi.frequency(16000000); wait_ms(500); cs = 0; @@ -59,6 +63,8 @@ printf("RAM mode: %02x\r\n", spi.write(0)); cs = 1; + printf("\r\nHELLO test\r\n"); + printf("RAM write\r\n"); strcpy(buf, "Hello!"); ram_write(0, buf, 6); @@ -68,7 +74,7 @@ } ram_write(6, buf, 256); - wait_ms(500); + wait(1); memset(buf, 0, 256); printf("RAM read\r\n"); @@ -79,10 +85,35 @@ printf("\r\n"); } - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + wait(1); + + printf("\r\nWrite/Read time\r\n"); + + printf("RAM write\r\n"); + t.reset(); + t.start(); + for (i = 0; i < 0x20000; i += 256) { + buf[0] = (i >> 8) & 0xff; + ram_write(i, buf, 256); + if ((i & 0x0fff) == 0) printf("."); } + t.stop(); + printf("\r\ntime %f, %f KBytes/sec\r\n", t.read(), (float)0x20000 / 1024 / t.read()); + + wait(1); + + printf("RAM read\r\n"); + t.reset(); + t.start(); + for (i = 0; i < 0x20000; i += 256) { + ram_read(i, buf, 256); + if (buf[0] != ((i >> 8) & 0xff)) { + printf("error %d\r\n", i); + break; + } + if ((i & 0x0fff) == 0) printf("."); + } + t.stop(); + printf("\r\ntime %f, %f KBytes/sec\r\n", t.read(), 0x20000 / 1024 / t.read()); + }