SPI

Dependencies:   mcp3008 mbed

Files at this revision

API Documentation at this revision

Comitter:
javiervicente
Date:
Tue Dec 01 11:55:38 2020 +0000
Parent:
4:0bd89699719e
Commit message:
Ejemplo SPI

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 0bd89699719e -r fa5a1d23025d main.cpp
--- a/main.cpp	Fri Nov 03 04:30:23 2017 +0000
+++ b/main.cpp	Tue Dec 01 11:55:38 2020 +0000
@@ -3,42 +3,29 @@
 
 #define SPI_CLOCK   (1312500)
 
+Serial pc(USBTX, USBRX); // tx, rx
+
 //SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
 SPI spiM(D4, D5, D3);
 MCP3008 mcp3008_0(&spiM, D6);
-MCP3008 mcp3008_1(&spiM, D7);
-MCP3008 mcp3008_2(&spiM, D8);
+
 
 int main()
 {
+    pc.baud(115200);
     spiM.frequency(SPI_CLOCK);
     
     uint16_t v0[8];
-    uint16_t v1[8];
-    uint16_t v2[8];
 
     for (;;) {
         for (int i = 0; i < 8; i++) {
             v0[i] = mcp3008_0.read_input_u16(i);
-            v1[i] = mcp3008_1.read_input_u16(i);
-            v2[i] = mcp3008_2.read_input_u16(i);
         }        
         
         for (int i = 0; i < 8; i++) {
-            printf("%4d\t", v0[i]);
-        }
-        
-        printf(": ");
-        for (int i = 0; i < 8; i++) {
-            printf("%4d\t", v1[i]);
-        }
-        
-        printf(": ");
-        for (int i = 0; i < 8; i++) {
-            printf("%4d\t", v2[i]);
-        }
-        
-        printf("\r\n");
+            pc.printf("%4d\t", v0[i]);
+        }             
+        pc.printf("\r\n");
         
         wait(0.2);
     }