Microchip 23K256 (SPI SRAM) sample code for https://www.switch-science.com/catalog/1072/ module.

Dependencies:   mbed

Revision:
4:b1021974c3e7
Parent:
3:65a33de8fa08
Child:
5:fb6ac7306443
--- a/main.cpp	Sun Nov 02 03:22:21 2014 +0000
+++ b/main.cpp	Mon Feb 16 04:08:20 2015 +0000
@@ -3,13 +3,6 @@
  *  - Microchip 23K256
  *    - SRAM
  *    - SPI 20MHz
- *  - Intersil ISL29125
- *    - Red/Green/Blue Color Light Sensor
- *    - I2C 500KHz, address = x100 0100, hard-wires
- *  - TAOS TSL2561
- *    - LUX Sensor
- *    - I2C 400kHz, address = x010 1001 (ADDR-GND), x011 1011 (ADDR-Float), x100 1001 (ADDR-VDD)
- *    - A/D conversion time: 12ms min, 100ms typ, 400ms max. 
  */
 
 #include "mbed.h"
@@ -28,6 +21,7 @@
         __nop();
     }
     pc.printf("USER button is pressed\r\n");
+    wait(0.2);
 }
 
 /** */
@@ -242,7 +236,7 @@
     // show data (to SERIAL)
     pc.printf("byte access test: result\r\n");
     for (int i = 0; i < size; i++) {
-        pc.printf("  %04x : %02x\r\n", i, buf[i]);
+        pc.printf("  %04x : %02x %s\r\n", i, buf[i], (buf[i] ==i)?"OK":"BAD");
     }
 }
 
@@ -272,7 +266,7 @@
     // show data (to SERIAL)
     pc.printf("page access test: result\r\n");
     for (int i = 0; i < size; i++) {
-        pc.printf("  %04x : %02x\r\n", address + i, buf[i]);
+        pc.printf("  %04x : %02x %s\r\n", address + i, buf[i], (buf[i] ==i)?"OK":"BAD");
     }
 }
 
@@ -303,26 +297,32 @@
     // show data (to SERIAL)
     pc.printf("sequential access test: result\r\n");
     for (int i = 0; i < size; i++) {
-        pc.printf("  %04x : %02x\r\n", address + i, buf[i]);
+        pc.printf("  %04x : %02x %s\r\n", address + i, buf[i], (buf[i] ==i)?"OK":"BAD");
     }
 }
 
 
+/**
+ *
+ * @pre SPI初期化済初期和美であること。バイトモードであること
+ */
 void
 try_single_byte_access() {
-    cs = 0;
-    spi.write(0x02u);
-    spi.write(0);
-    spi.write(0);
-    spi.write(0x5a);
-    cs = 1;
+    // 1byte write
+    assert_CS();
+    spi.write(0x02u);   // write command
+    spi.write(0);       // address
+    spi.write(0);       // address
+    spi.write(0x5a);    // data
+    nagate_CS();
     
-    cs = 0;
-    spi.write(0x03u);
-    spi.write(0);
-    spi.write(0);
-    const uint8_t value = spi.write(0);
-    cs = 1;
+    // 1byte read
+    assert_CS();
+    spi.write(0x03u);   // read command
+    spi.write(0);       // address
+    spi.write(0);       // address
+    const uint8_t value = spi.write(0); // data
+    nagate_CS();
 
     pc.printf("read: 0x%02x\r\n", value);
 }
@@ -334,6 +334,7 @@
 int
 main()
 {
+    pc.baud(115200);
     pc.printf("CPU SystemCoreClock is %.2f MHz\r\n", (float)SystemCoreClock/1.0e6f);
 
     // initialize SPI