SPI library used to communicate with an altera development board attached to four zigbee-header pins.

Revision:
23:dbd89a56716d
Parent:
22:7524dee5c753
Child:
24:d3b8c68f41f2
--- a/mmSPI.cpp	Tue Aug 20 14:13:32 2013 +0000
+++ b/mmSPI.cpp	Tue Aug 20 14:25:47 2013 +0000
@@ -68,14 +68,9 @@
       dNumBytes = dNumberOfBytes;               // promote to object scope.
     }
 //----------------------------------------------//------------------------------
-
-
-
-
                                                 // transceive a character array.
-                                                // limit is 256 characters.
                                                 // MSB out/in first.
-    void mmSPI::transceive_vector(char *pcReceive, char *pcSend, int dNumBytes)
+    void mmSPI::transceive_vector(void)
     {      
       int  dClear;
       int  dIndex;       
@@ -127,7 +122,7 @@
       }
     }
 //----------------------------------------------//------------------------------
-    void mmSPI::write_register(char cRegister, char cValue, char * pcReceive, char * pcSend)
+    void mmSPI::write_register(char cRegister, char cValue)
     {     
       int dLoop;                                // loop index.
       
@@ -140,7 +135,7 @@
       pcSend[1] = ((cRegister & 0x07) << 2) | 0xA0;
       pcSend[0] = cValue & 0xFF;                // immediate value to i.w.
  
-      transceive_vector(pcReceive, pcSend, 8); // transmit command.
+      transceive_vector();                      // transmit command.
  
                                                 // clear transmit vector.
       for (dLoop = 0; dLoop < 8; dLoop++) pcSend[dLoop] = 0x00; 
@@ -148,7 +143,7 @@
 //----------------------------------------------//------------------------------
                                                 // returns the content of
                                                 // a CPU register.
-    char mmSPI::read_register(char cRegister, char * pcReceive, char * pcSend)
+    char mmSPI::read_register(char cRegister)
     { 
       int dLoop;      
 
@@ -156,12 +151,12 @@
                                                 // send all 0.
       for (dLoop = 0; dLoop < 8; dLoop++) pcSend[dLoop] = 0x00;    
                    
-      transceive_vector(pcReceive, pcSend, 8); // snap & scan-out reg contents.
+      transceive_vector();                      // snap & scan-out reg contents.
       
       return (pcReceive[6 - cRegister]);        // return the particular reg value.
     }
 //----------------------------------------------//------------------------------
-    void mmSPI::write_memory(char cHData, char cLdata, char cAddress, char * pcReceive, char * pcSend)
+    void mmSPI::write_memory(char cHData, char cLdata, char cAddress)
     {
       int dLoop;                                // loop index.
     
@@ -171,19 +166,19 @@
                                                 // R3 <- address.
                                                 // R2 <- high-data.
                                                 // R1 <- low-data.
-      write_register(0x03,cAddress, pcReceive, pcSend); 
-      write_register(0x02,cHData,   pcReceive, pcSend);
-      write_register(0x01,cLdata,   pcReceive, pcSend);
+      write_register(0x03,cAddress); 
+      write_register(0x02,cHData);
+      write_register(0x01,cLdata);
   
       pcSend[7] = 0x00;                         // write-enable high.
       pcSend[1] = 0x02;
       pcSend[0] = 0x00;
-      transceive_vector(pcReceive, pcSend, 8);
+      transceive_vector();
       
       pcSend[7] = 0x00;                         // write-enable low.
       pcSend[1] = 0x00;
       pcSend[0] = 0x00;
-      transceive_vector(pcReceive, pcSend, 8);   
+      transceive_vector();   
       
                                                 // clear transmit vector.
       for (dLoop = 0; dLoop < 8; dLoop++) pcSend[dLoop] = 0x00; 
@@ -191,7 +186,7 @@
     }
 //----------------------------------------------//------------------------------
                                                 // fetch a word from main memory.
-    unsigned int mmSPI::read_memory(char cAddress, char * pcReceive, char * pcSend)
+    unsigned int mmSPI::read_memory(char cAddress)
     {
       int          dLoop;                       // loop index.   
       unsigned int udMemoryContent;             // return variable.
@@ -203,21 +198,21 @@
             
       
                                                 // R3 <- address.
-      write_register(0x03,cAddress, pcReceive, pcSend);
+      write_register(0x03,cAddress);
       
       pcSend[7] = 0x02;                         // mbed sends command.
       pcSend[1] = 0xC8;                         // R2 <- MM[R3]
       pcSend[0] = 0x00;
-      transceive_vector(pcReceive, pcSend, 8); // send command. 
+      transceive_vector();                      // send command. 
       
       pcSend[7] = 0x02;                         // mbed sends command.
       pcSend[1] = 0xC4;                         // R1 <- MM[R3]
       pcSend[0] = 0x00;
-      transceive_vector(pcReceive, pcSend, 8); // send command.      
+      transceive_vector();                      // send command.      
            
                                                 // obtain MM content.
-      cHData = read_register(0x02, pcReceive, pcSend);  
-      cLData = read_register(0x01, pcReceive, pcSend);    
+      cHData = read_register(0x02);  
+      cLData = read_register(0x01);    
     
                                                 
       udMemoryContent = (cHData << 8) + cLData; // build the memory word.