Albert-Jan Knevels / Mbed 2 deprecated CherryStone

Dependencies:   mbed

Revision:
17:0dee2d58c357
Parent:
16:62feeff507d5
Child:
18:1fddc3e5fffe
diff -r 62feeff507d5 -r 0dee2d58c357 main.cpp
--- a/main.cpp	Wed Oct 29 12:03:57 2014 +0000
+++ b/main.cpp	Wed Oct 29 13:18:21 2014 +0000
@@ -22,33 +22,37 @@
 #include "MLX90393.h"
 int main()
 {
-    //watchdog timer
-    //WatchdogTimer wdt;
-
     //mBed indicators
-    DigitalOut myled(LED1);
+    DigitalOut a1(p21);
+    DigitalOut a0(p22);
 
     //PC-communication
     Serial pc (USBTX, USBRX);
     pc.baud(9600);
-    char hostCommand;
-    int hostData1;
-    int hostData2;
-    int hostData3;
-    //Chip communication
-    SPI spi(p5, p6, p7);
+
+    //variables
+    int hostData1,hostData2,hostData3, content_buffer[63];
+    unsigned int dataInteger0, dataInteger1, dataInteger2;
+    char read_buffer[11], hostCommand;
+
+    //Chip communication (SPI)
+    /*SPI spi(p5, p6, p7);
     spi.format(MLX90393::spi_bits,MLX90393::spi_mode);
     spi.frequency(100000000);
     MLX90393 sensor(p8,&spi);
+    */
+    
+    //Chip communication (I2C)
+    a1=0;
+    a0=0;
+    I2C i2c(p9, p10);
+    i2c.frequency(75000);
+    MLX90393 sensor(MLX90393::i2c_address,&i2c);
 
-    //variables
-    char read_buffer[11];
-    int content_buffer[63];
-    unsigned int dataInteger0;
-    unsigned int dataInteger1;
-    unsigned int dataInteger2;
+
     //if you remove this line the program will fail
     //also make sure that you always send the status back to the host
+
     hostCommand = 0;
     while(1) {
         pc.scanf(" %i, %i, %i, %i", &hostCommand, &hostData1, &hostData2, &hostData3);
@@ -62,7 +66,7 @@
             case 1: {
                 //read eeprom full (implemeted CS)
                 for (int i = 0; i<63; i++) {
-                    sensor.RR(read_buffer,i,1);
+                    sensor.RR(read_buffer,i,hostData1);
                     content_buffer[i] = (read_buffer[0]*65536)+(read_buffer[1]*256) + read_buffer[2];
                 }
                 for (int i = 0; i<63; i++) {
@@ -113,7 +117,7 @@
             }
             case 9: {
                 //wake up on change (Implemented in cs)
-                sensor.SWOC(read_buffer,hostData1,1);
+                sensor.SWOC(read_buffer,hostData1,hostData2);
                 printf("%i\n",read_buffer[0]);
                 break;
             }