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
- Committer:
- Rhyme
- Date:
- 2017-03-28
- Revision:
- 2:05ddb1d95e2a
- Parent:
- 1:c92b1fb10573
File content as of revision 2:05ddb1d95e2a:
#include <ctype.h> #include "mbed.h" // #include "serial_api.h" #include "vt100.h" #include "SPI_IS25LQ032B.h" vt100 *tty = 0 ; // SPI_IS25LQ032B(PinName mosi, PinName miso, PinName sclk, PinName cs) ; #if defined (TARGET_KL25Z) #define SPI1_SCLK PTD1 #define SPI1_MISO PTD3 #define SPI1_MOSI PTD2 #define SPI1_PCS0 PTD0 #elif defined (TARGET_K22F) #define SPI1_SCLK PTD5 #define SPI1_MISO PTD7 #define SPI1_MOSI PTD6 #define SPI1_PCS0 PTC0 #endif SPI_IS25LQ032B spi_mem(SPI1_MOSI, SPI1_MISO, SPI1_SCLK, SPI1_PCS0) ; void usage(void) { printf("=== commands ===\n\r") ; printf("read address (ex: read 0x0000)\n\r") ; printf("dump address (ex: dump 0x2000)\n\r") ; printf("rdsr (read status register)\n\r") ; printf("wrsr value (write status register: ex wrsr 0x00)\n\r") ; printf("rdfr (read function register)\n\r") ; printf("wrfr value (write functions register: ex wrfr 0x00)\n\r") ; printf("wren (write enable)\n\r") ; printf("wrdi (write disable)\n\r") ; printf("write address value (program a 8bit data to address)\n\r") ; printf("pp address (program page: ex pp 0x00)\n\r") ; printf("cer (chip erase)\n\r") ; printf("\n\r") ; } void dump(unsigned long address) { unsigned int i, j ; unsigned char data[0x10] ; printf(" : ") ; for (i = 0 ; i < 0x10 ; i++ ) { printf("+%X ",i) ; } printf("\n\r") ; for (j = 0 ; j < 0x10 ; j++ ) { printf("%06X : ", address + (0x10 * j)) ; for (i = 0 ; i < 0x10 ; i++ ) { data[i] = spi_mem.read8(address + 0x10 * j + i) ; printf("%02X ", data[i]) ; } printf(": ") ; for (i = 0 ; i < 0x10 ; i++ ) { if (isprint(data[i])) { printf("%c", data[i]) ; } else { printf(".") ; } } printf(" :\n\r") ; } printf("\n\r") ; } int main() { char cmd[32] ; int tmp = 0 ; int i ; int numData = 256 ; unsigned long address = 0 ; unsigned char data[256] ; // extern serial_t stdio_uart ; // serial_baud(&stdio_uart, 115200) ; tty = new vt100() ; tty->cls() ; printf("\n\r============================\n\r") ; printf("IS25LQ032B test program\n\r") ; printf("please enable local echo\n\r") ; printf("============================\n\r") ; printf("\n\r") ; usage() ; while(1) { printf("> ") ; scanf("%s", cmd) ; if (strcmp(cmd, "read") == 0) { scanf("%X", &address) ; data[0] = spi_mem.read8(address) ; printf("%08X : 0x%02X\n\r", address, data[0]) ; } else if (strcmp(cmd, "rdsr") == 0) { // read status data[0] = spi_mem.readStatus() ; printf("status register = 0x%02X\n\r", data[0]) ; } else if (strcmp(cmd, "wrsr") == 0) { // write satus scanf("%X", &tmp) ; spi_mem.writeStatus(tmp) ; } else if (strcmp(cmd, "rdfr") == 0) { // read function data[0] = spi_mem.readFunc() ; printf("function register = 0x%02X\n\r", data[0]) ; } else if (strcmp(cmd, "wrfr") == 0) { // write fucntion scanf("%X", &tmp) ; spi_mem.writeFunc(tmp) ; printf("done\n\r") ; } else if (strcmp(cmd, "wren") == 0) { // write enable spi_mem.writeEnable() ; printf("done\n\r") ; } else if (strcmp(cmd, "wrdi") == 0) { // write disable spi_mem.writeDisable() ; printf("done\n\r") ; } else if (strcmp(cmd, "write") == 0) { // write a byte scanf("%X", &address) ; scanf("%X", &tmp) ; data[0] = tmp & 0xFF ; printf("mem[0x%06X] <= 0x%02X\n\r",address, data[0]) ; spi_mem.writeEnable() ; spi_mem.programPage(address, data, 1) ; printf("done\n\r") ; } else if (strcmp(cmd, "pp") == 0) { // program page scanf("%X", &address) ; printf("writing %d bytes to 0x%X\n\r",numData, address) ; spi_mem.writeEnable() ; for (i = 0 ; i < numData ; i++ ) { data[i] = i & 0xFF ; } spi_mem.programPage(address, data, numData) ; data[0] = 0 ; while((data[0] & 0x01) != 0x01 ) { printf(".") ; data[0] = spi_mem.readStatus() ; wait(0.01) ; } printf("\n\r") ; } else if (strcmp(cmd, "cer") == 0) { // chip erase printf("Erasing chip\n\r") ; spi_mem.writeEnable() ; spi_mem.chipErase() ; printf("done\n\r") ; } else if (strcmp(cmd, "dump") == 0) { scanf("%X", &address) ; dump(address) ; } else if (strcmp(cmd, "help") == 0) { usage() ; } else { printf("Unknown command [ %s ]\n\r", cmd) ; usage() ; } } }