![](/media/cache/profiles/0d382a5fec7012c843c1bdfb0935c9a6.50x50_q85.jpg)
a test program for my SPI_IS25LQ032B library. please set local-echo on for the terminal program.
Dependencies: SPI_IS25LQ032B mbed vt100
At start up the program show the list of available commands
起動すると、使用出来るコマンドの一覧が表示されます。
To see the contents of the first 256 bytes of memory, type
dump 0x00
最初の256バイトを表示させるのには dump 0x00 と入力してください。
Let's write a value 0xA5 to address 0x10
write 0x10 0xA5
Then see the result with
dump 0x00
先ず、アドレス 0x10 に 0xA5 を書き込みます。 write 0x10 0xA5
その結果を再度 dump 0x00 コマンドで表示させると
To erase the entire memory, use command
cer
メモリ全体を初期化するのには cer コマンドを使用してください。
main.cpp@2:05ddb1d95e2a, 2017-03-28 (annotated)
- Committer:
- Rhyme
- Date:
- Tue Mar 28 01:24:40 2017 +0000
- Revision:
- 2:05ddb1d95e2a
- Parent:
- 1:c92b1fb10573
support of quattro-II & f-shaft II added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:a9c975f17ca4 | 1 | #include <ctype.h> |
Rhyme | 0:a9c975f17ca4 | 2 | #include "mbed.h" |
Rhyme | 2:05ddb1d95e2a | 3 | // #include "serial_api.h" |
Rhyme | 2:05ddb1d95e2a | 4 | #include "vt100.h" |
Rhyme | 0:a9c975f17ca4 | 5 | #include "SPI_IS25LQ032B.h" |
Rhyme | 0:a9c975f17ca4 | 6 | |
Rhyme | 2:05ddb1d95e2a | 7 | vt100 *tty = 0 ; |
Rhyme | 2:05ddb1d95e2a | 8 | |
Rhyme | 0:a9c975f17ca4 | 9 | // SPI_IS25LQ032B(PinName mosi, PinName miso, PinName sclk, PinName cs) ; |
Rhyme | 2:05ddb1d95e2a | 10 | #if defined (TARGET_KL25Z) |
Rhyme | 2:05ddb1d95e2a | 11 | #define SPI1_SCLK PTD1 |
Rhyme | 2:05ddb1d95e2a | 12 | #define SPI1_MISO PTD3 |
Rhyme | 2:05ddb1d95e2a | 13 | #define SPI1_MOSI PTD2 |
Rhyme | 2:05ddb1d95e2a | 14 | #define SPI1_PCS0 PTD0 |
Rhyme | 2:05ddb1d95e2a | 15 | #elif defined (TARGET_K22F) |
Rhyme | 2:05ddb1d95e2a | 16 | #define SPI1_SCLK PTD5 |
Rhyme | 2:05ddb1d95e2a | 17 | #define SPI1_MISO PTD7 |
Rhyme | 2:05ddb1d95e2a | 18 | #define SPI1_MOSI PTD6 |
Rhyme | 2:05ddb1d95e2a | 19 | #define SPI1_PCS0 PTC0 |
Rhyme | 1:c92b1fb10573 | 20 | #endif |
Rhyme | 2:05ddb1d95e2a | 21 | SPI_IS25LQ032B spi_mem(SPI1_MOSI, SPI1_MISO, SPI1_SCLK, SPI1_PCS0) ; |
Rhyme | 0:a9c975f17ca4 | 22 | |
Rhyme | 0:a9c975f17ca4 | 23 | void usage(void) |
Rhyme | 0:a9c975f17ca4 | 24 | { |
Rhyme | 0:a9c975f17ca4 | 25 | printf("=== commands ===\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 26 | printf("read address (ex: read 0x0000)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 27 | printf("dump address (ex: dump 0x2000)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 28 | printf("rdsr (read status register)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 29 | printf("wrsr value (write status register: ex wrsr 0x00)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 30 | printf("rdfr (read function register)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 31 | printf("wrfr value (write functions register: ex wrfr 0x00)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 32 | printf("wren (write enable)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 33 | printf("wrdi (write disable)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 34 | printf("write address value (program a 8bit data to address)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 35 | printf("pp address (program page: ex pp 0x00)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 36 | printf("cer (chip erase)\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 37 | printf("\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 38 | } |
Rhyme | 0:a9c975f17ca4 | 39 | |
Rhyme | 0:a9c975f17ca4 | 40 | void dump(unsigned long address) |
Rhyme | 0:a9c975f17ca4 | 41 | { |
Rhyme | 0:a9c975f17ca4 | 42 | unsigned int i, j ; |
Rhyme | 0:a9c975f17ca4 | 43 | unsigned char data[0x10] ; |
Rhyme | 0:a9c975f17ca4 | 44 | |
Rhyme | 0:a9c975f17ca4 | 45 | printf(" : ") ; |
Rhyme | 0:a9c975f17ca4 | 46 | for (i = 0 ; i < 0x10 ; i++ ) { |
Rhyme | 0:a9c975f17ca4 | 47 | printf("+%X ",i) ; |
Rhyme | 0:a9c975f17ca4 | 48 | } |
Rhyme | 0:a9c975f17ca4 | 49 | printf("\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 50 | for (j = 0 ; j < 0x10 ; j++ ) { |
Rhyme | 0:a9c975f17ca4 | 51 | printf("%06X : ", address + (0x10 * j)) ; |
Rhyme | 0:a9c975f17ca4 | 52 | for (i = 0 ; i < 0x10 ; i++ ) { |
Rhyme | 0:a9c975f17ca4 | 53 | data[i] = spi_mem.read8(address + 0x10 * j + i) ; |
Rhyme | 0:a9c975f17ca4 | 54 | printf("%02X ", data[i]) ; |
Rhyme | 0:a9c975f17ca4 | 55 | } |
Rhyme | 0:a9c975f17ca4 | 56 | printf(": ") ; |
Rhyme | 0:a9c975f17ca4 | 57 | for (i = 0 ; i < 0x10 ; i++ ) { |
Rhyme | 0:a9c975f17ca4 | 58 | if (isprint(data[i])) { |
Rhyme | 0:a9c975f17ca4 | 59 | printf("%c", data[i]) ; |
Rhyme | 0:a9c975f17ca4 | 60 | } else { |
Rhyme | 0:a9c975f17ca4 | 61 | printf(".") ; |
Rhyme | 0:a9c975f17ca4 | 62 | } |
Rhyme | 0:a9c975f17ca4 | 63 | } |
Rhyme | 0:a9c975f17ca4 | 64 | printf(" :\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 65 | } |
Rhyme | 0:a9c975f17ca4 | 66 | printf("\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 67 | } |
Rhyme | 0:a9c975f17ca4 | 68 | |
Rhyme | 0:a9c975f17ca4 | 69 | int main() { |
Rhyme | 0:a9c975f17ca4 | 70 | char cmd[32] ; |
Rhyme | 0:a9c975f17ca4 | 71 | int tmp = 0 ; |
Rhyme | 0:a9c975f17ca4 | 72 | int i ; |
Rhyme | 0:a9c975f17ca4 | 73 | int numData = 256 ; |
Rhyme | 0:a9c975f17ca4 | 74 | unsigned long address = 0 ; |
Rhyme | 0:a9c975f17ca4 | 75 | unsigned char data[256] ; |
Rhyme | 0:a9c975f17ca4 | 76 | |
Rhyme | 2:05ddb1d95e2a | 77 | // extern serial_t stdio_uart ; |
Rhyme | 2:05ddb1d95e2a | 78 | // serial_baud(&stdio_uart, 115200) ; |
Rhyme | 2:05ddb1d95e2a | 79 | tty = new vt100() ; |
Rhyme | 2:05ddb1d95e2a | 80 | tty->cls() ; |
Rhyme | 0:a9c975f17ca4 | 81 | |
Rhyme | 0:a9c975f17ca4 | 82 | printf("\n\r============================\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 83 | printf("IS25LQ032B test program\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 84 | printf("please enable local echo\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 85 | printf("============================\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 86 | printf("\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 87 | usage() ; |
Rhyme | 0:a9c975f17ca4 | 88 | |
Rhyme | 0:a9c975f17ca4 | 89 | while(1) { |
Rhyme | 0:a9c975f17ca4 | 90 | printf("> ") ; |
Rhyme | 0:a9c975f17ca4 | 91 | scanf("%s", cmd) ; |
Rhyme | 0:a9c975f17ca4 | 92 | if (strcmp(cmd, "read") == 0) { |
Rhyme | 0:a9c975f17ca4 | 93 | scanf("%X", &address) ; |
Rhyme | 0:a9c975f17ca4 | 94 | data[0] = spi_mem.read8(address) ; |
Rhyme | 0:a9c975f17ca4 | 95 | printf("%08X : 0x%02X\n\r", address, data[0]) ; |
Rhyme | 0:a9c975f17ca4 | 96 | } else if (strcmp(cmd, "rdsr") == 0) { // read status |
Rhyme | 0:a9c975f17ca4 | 97 | data[0] = spi_mem.readStatus() ; |
Rhyme | 0:a9c975f17ca4 | 98 | printf("status register = 0x%02X\n\r", data[0]) ; |
Rhyme | 0:a9c975f17ca4 | 99 | } else if (strcmp(cmd, "wrsr") == 0) { // write satus |
Rhyme | 0:a9c975f17ca4 | 100 | scanf("%X", &tmp) ; |
Rhyme | 0:a9c975f17ca4 | 101 | spi_mem.writeStatus(tmp) ; |
Rhyme | 0:a9c975f17ca4 | 102 | } else if (strcmp(cmd, "rdfr") == 0) { // read function |
Rhyme | 0:a9c975f17ca4 | 103 | data[0] = spi_mem.readFunc() ; |
Rhyme | 0:a9c975f17ca4 | 104 | printf("function register = 0x%02X\n\r", data[0]) ; |
Rhyme | 0:a9c975f17ca4 | 105 | } else if (strcmp(cmd, "wrfr") == 0) { // write fucntion |
Rhyme | 0:a9c975f17ca4 | 106 | scanf("%X", &tmp) ; |
Rhyme | 0:a9c975f17ca4 | 107 | spi_mem.writeFunc(tmp) ; |
Rhyme | 0:a9c975f17ca4 | 108 | printf("done\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 109 | } else if (strcmp(cmd, "wren") == 0) { // write enable |
Rhyme | 0:a9c975f17ca4 | 110 | spi_mem.writeEnable() ; |
Rhyme | 0:a9c975f17ca4 | 111 | printf("done\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 112 | } else if (strcmp(cmd, "wrdi") == 0) { // write disable |
Rhyme | 0:a9c975f17ca4 | 113 | spi_mem.writeDisable() ; |
Rhyme | 0:a9c975f17ca4 | 114 | printf("done\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 115 | } else if (strcmp(cmd, "write") == 0) { // write a byte |
Rhyme | 0:a9c975f17ca4 | 116 | scanf("%X", &address) ; |
Rhyme | 0:a9c975f17ca4 | 117 | scanf("%X", &tmp) ; |
Rhyme | 0:a9c975f17ca4 | 118 | data[0] = tmp & 0xFF ; |
Rhyme | 0:a9c975f17ca4 | 119 | printf("mem[0x%06X] <= 0x%02X\n\r",address, data[0]) ; |
Rhyme | 0:a9c975f17ca4 | 120 | spi_mem.writeEnable() ; |
Rhyme | 0:a9c975f17ca4 | 121 | spi_mem.programPage(address, data, 1) ; |
Rhyme | 0:a9c975f17ca4 | 122 | printf("done\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 123 | } else if (strcmp(cmd, "pp") == 0) { // program page |
Rhyme | 0:a9c975f17ca4 | 124 | scanf("%X", &address) ; |
Rhyme | 0:a9c975f17ca4 | 125 | printf("writing %d bytes to 0x%X\n\r",numData, address) ; |
Rhyme | 0:a9c975f17ca4 | 126 | spi_mem.writeEnable() ; |
Rhyme | 0:a9c975f17ca4 | 127 | for (i = 0 ; i < numData ; i++ ) { |
Rhyme | 0:a9c975f17ca4 | 128 | data[i] = i & 0xFF ; |
Rhyme | 0:a9c975f17ca4 | 129 | } |
Rhyme | 0:a9c975f17ca4 | 130 | spi_mem.programPage(address, data, numData) ; |
Rhyme | 0:a9c975f17ca4 | 131 | data[0] = 0 ; |
Rhyme | 0:a9c975f17ca4 | 132 | while((data[0] & 0x01) != 0x01 ) { |
Rhyme | 0:a9c975f17ca4 | 133 | printf(".") ; |
Rhyme | 0:a9c975f17ca4 | 134 | data[0] = spi_mem.readStatus() ; |
Rhyme | 0:a9c975f17ca4 | 135 | wait(0.01) ; |
Rhyme | 0:a9c975f17ca4 | 136 | } |
Rhyme | 0:a9c975f17ca4 | 137 | printf("\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 138 | } else if (strcmp(cmd, "cer") == 0) { // chip erase |
Rhyme | 0:a9c975f17ca4 | 139 | printf("Erasing chip\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 140 | spi_mem.writeEnable() ; |
Rhyme | 0:a9c975f17ca4 | 141 | spi_mem.chipErase() ; |
Rhyme | 0:a9c975f17ca4 | 142 | printf("done\n\r") ; |
Rhyme | 0:a9c975f17ca4 | 143 | } else if (strcmp(cmd, "dump") == 0) { |
Rhyme | 0:a9c975f17ca4 | 144 | scanf("%X", &address) ; |
Rhyme | 0:a9c975f17ca4 | 145 | dump(address) ; |
Rhyme | 0:a9c975f17ca4 | 146 | } else if (strcmp(cmd, "help") == 0) { |
Rhyme | 0:a9c975f17ca4 | 147 | usage() ; |
Rhyme | 0:a9c975f17ca4 | 148 | } else { |
Rhyme | 0:a9c975f17ca4 | 149 | printf("Unknown command [ %s ]\n\r", cmd) ; |
Rhyme | 0:a9c975f17ca4 | 150 | usage() ; |
Rhyme | 0:a9c975f17ca4 | 151 | } |
Rhyme | 0:a9c975f17ca4 | 152 | } |
Rhyme | 0:a9c975f17ca4 | 153 | } |