Microchip SPI SRAM 23LC1024 demo

Dependencies:   mbed

Revision:
2:e0d7ea47d2a5
Parent:
1:4b45ee2c9b51
Child:
3:b585283f5932
--- a/main.cpp	Mon Nov 09 12:05:33 2015 +0000
+++ b/main.cpp	Mon Nov 09 12:12:01 2015 +0000
@@ -110,9 +110,8 @@
 
 /**
  * 1byte read
- * @param[in] address アドレス 16bit。容量32KBなので、MSBは無視する
+ * @param[in] address アドレス 24bit
  * @return データ
- * @pre byteモードに切り替えていること。
  */
 uint8_t
 read_byte(const uint32_t address) {
@@ -133,9 +132,8 @@
 
 /**
  * 1byte write
- * @param[in] address アドレス 16bit。容量32KBなので、MSBは無視する
+ * @param[in] address アドレス 24bit
  * @param[in] data データ
- * @pre byteモードに切り替えていること。
  */
 void
 write_byte(const uint32_t address, const uint8_t data) {
@@ -154,7 +152,7 @@
 
 /**
  * 連続読み出し
- * @pre pageモードかbyteモードに切り替えていること。
+ * @pre sequentialモードかpageモードに切り替えていること。
  */
 void
 read_bytes(const uint32_t address, uint8_t __restrict data[], const uint32_t size) {
@@ -175,7 +173,7 @@
 
 /**
  * 連続書き込み
- * @pre pageモードかbyteモードに切り替えていること。
+ * @pre sequentialモードかpageモードに切り替えていること。
  */
 void
 write_bytes(const uint32_t address, const uint8_t __restrict data[], const uint32_t size) {
@@ -203,7 +201,7 @@
 uint8_t buf[256] = {};
 
 /**
- * 動作確認用。TODO: テストコードにすること。
+ * byteアクセスを複数回実行して、照合する
  */
 void
 try_byte_access() {
@@ -227,35 +225,35 @@
 }
 
 /**
- * 動作確認用。TODO: テストコードにすること。
+ * pageアクセスを実行して、照合する
  */
 void
 try_page_access() {
     const uint32_t address = 0x1000;
-    const uint32_t size = 32;
+    const uint32_t page_size = 32;
 
     // write
-    for (uint32_t i = 0; i < size; ++i) {
+    for (uint32_t i = 0; i < page_size; ++i) {
         buf[i] = i;
     }
-    write_bytes(address, buf, size);
+    write_bytes(address, buf, page_size);
 
     // read
-    for (uint32_t i = 0; i < size; ++i) {
+    for (uint32_t i = 0; i < page_size; ++i) {
         buf[i] = 0;
     }
 
-    read_bytes(address, buf, size);
+    read_bytes(address, buf, page_size);
 
     // show data (to SERIAL)
     pc.printf("page access test: result\r\n");
-    for (int i = 0; i < size; i++) {
+    for (int i = 0; i < page_size; i++) {
         pc.printf("  %04x : %02x %s\r\n", address + i, buf[i], (buf[i] ==i)?"OK":"BAD");
     }
 }
 
 /**
- * 動作確認用。TODO: テストコードにすること。
+ * sequentialアクセスを実行して、照合する
  */
 void
 try_sequential_access() {
@@ -283,10 +281,9 @@
     }
 }
 
-
 /**
- *
- * @pre SPI初期化済初期和美であること。バイトモードであること
+ * 動作確認のために、spiオブジェクトを直接使って読み書きする。
+ * @pre SPI初期化ずみであること。
  */
 void
 try_single_byte_access() {
@@ -318,7 +315,8 @@
     const uint8_t value = spi.write(0);
     cs = 1;
 
-    pc.printf("write: %02x -> read: %02x\r\n", data, value);
+    pc.printf("single byte access test: result\r\n");
+      pc.printf("write: %02x -> read: %02x\r\n", data, value);
 }