v2.0 working

Dependencies:   mbed

Revision:
2:2b08032d9678
Parent:
0:8ed3ad791ca2
diff -r 436d836f2b8e -r 2b08032d9678 SDCard_initionalisation.h
--- a/SDCard_initionalisation.h	Thu Jul 30 10:53:26 2015 +0000
+++ b/SDCard_initionalisation.h	Thu Jul 30 12:39:50 2015 +0000
@@ -1,6 +1,6 @@
 
 Serial PC(USBTX, USBRX);
-DigitalOut cs(D9);
+DigitalOut cs_SDCard(D9);
 
 #define SD_COMMAND_TIMEOUT 5000
 
@@ -48,7 +48,7 @@
 
 
 void initialisation_SDCard(){ 
-    CS =1;
+    cs_adf =1;
 //    start_block_num =10 ;           // Read from TC
 //    end_block_num =Science_TMframe::SDC_address ;            // Read from TC    
     printf("welcome\n");
@@ -64,9 +64,9 @@
 
 int initialise_card()
 {
-    // Set to 100kHz for initialisation, and clock card with cs = 1
+    // Set to 100kHz for initialisation, and clock card with cs_SDCard = 1
     spi.frequency(100000);
-    cs = 1;
+    cs_SDCard = 1;
     for (int i = 0; i < 16; i++) {
         spi.write(0xFF);
     }
@@ -133,7 +133,7 @@
 
 int cmd(int cmd, int arg)
 {
-    cs = 0;
+    cs_SDCard = 0;
 
     // send a command
     spi.write(0x40 | cmd);
@@ -147,12 +147,12 @@
     for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) {
         int response = spi.write(0xFF);
         if (!(response & 0x80)) {
-            cs = 1;
+            cs_SDCard = 1;
             spi.write(0xFF);
             return response;
         }
     }
-    cs = 1;
+    cs_SDCard = 1;
     spi.write(0xFF);
     return -1; // timeout
 }
@@ -160,7 +160,7 @@
 
 int cmd58()
 {
-    cs = 0;
+    cs_SDCard = 0;
     int arg = 0;
 
     // send a command
@@ -179,12 +179,12 @@
             ocr |= spi.write(0xFF) << 16;
             ocr |= spi.write(0xFF) << 8;
             ocr |= spi.write(0xFF) << 0;
-            cs = 1;
+            cs_SDCard = 1;
             spi.write(0xFF);
             return response;
         }
     }
-    cs = 1;
+    cs_SDCard = 1;
     spi.write(0xFF);
     return -1; // timeout
 }
@@ -192,7 +192,7 @@
 
 int cmd8()
 {
-    cs = 0;
+    cs_SDCard = 0;
 
     // send a command
     spi.write(0x40 | 8); // CMD8
@@ -210,12 +210,12 @@
             for (int j = 1; j < 5; j++) {
                 response[i] = spi.write(0xFF);
             }
-            cs = 1;
+            cs_SDCard = 1;
             spi.write(0xFF);
             return response[0];
         }
     }
-    cs = 1;
+    cs_SDCard = 1;
     spi.write(0xFF);
     return -1; // timeout
 }
@@ -277,7 +277,7 @@
 
 int cmdx(int cmd, int arg)
 {
-    cs = 0;
+    cs_SDCard = 0;
 
     // send a command
     spi.write(0x40 | cmd);
@@ -294,7 +294,7 @@
             return response;
         }
     }
-    cs = 1;
+    cs_SDCard = 1;
     spi.write(0xFF);
     return -1; // timeout
 }
@@ -347,7 +347,7 @@
 
 int write(const uint8_t*buffer, uint32_t length)
 {
-    cs = 0;
+    cs_SDCard = 0;
 
     // indicate start of block
     spi.write(0xFE);
@@ -363,7 +363,7 @@
 
     // check the response token
     if ((spi.write(0xFF) & 0x1F) != 0x05) {
-        cs = 1;
+        cs_SDCard = 1;
         spi.write(0xFF);
         return 1;
     }
@@ -371,7 +371,7 @@
     // wait for write to finish
     while (spi.write(0xFF) == 0);
 
-    cs = 1;
+    cs_SDCard = 1;
     spi.write(0xFF);
     return 0;
 }
@@ -390,7 +390,7 @@
 
 int read(uint8_t *buffer, uint32_t length)
 {
-    cs = 0;
+    cs_SDCard = 0;
 
     // read until start byte (0xFF)
     while (spi.write(0xFF) != 0xFE);
@@ -402,7 +402,7 @@
     spi.write(0xFF); // checksum
     spi.write(0xFF);
 
-    cs = 1;
+    cs_SDCard = 1;
     spi.write(0xFF);
     return 0;
 }