]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
Magn Sens: New commands for reading/writing/storing
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 8 Feb 2018 13:08:17 +0000 (14:08 +0100)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 8 Feb 2018 13:08:45 +0000 (14:08 +0100)
sensors/MagneticFieldSensor/main.c

index f51c346174db56fc6cc61ade0943f82bd137aaa0..ee685c630dfd224aab25e0a764295067f1013696 100644 (file)
@@ -76,7 +76,7 @@ int main(void)
              uputsnl(s);\r
              \r
            } else if (mode != 0) {\r
-              \r
+              // CONFIG mode\r
               unsigned position = 0;\r
               char * ptr;\r
               ptr = strtok(uart_string," ");\r
@@ -142,26 +142,32 @@ int main(void)
              \r
              \r
              \r
-             if (Command[0] == 1){\r
+             if (Command[0] == 0x6){\r
                    Command[0] = 0x60; // write\r
                    Command[3] = (Command[3]<<2) & 0xff;\r
-                   // <I2c Address> <Write:1> <Data15:0> <Data7:0> <RegAddress>\r
+                   // <I2c Address> <Write:6> <Data15:0> <Data7:0> <RegAddress>\r
                    status2 = twi_writeTo(I2C_Address, Command, 4,1, true);\r
                    twi_readFrom(I2C_Address, &status, 1, true);\r
                    sprintf(s,"Status: 0x%x | Write Command: Data[15:8]  0x%x   Data[7:0]  0x%x     RegAddress:  0x%x",status[0], Command[1],Command[2],Command[3]);\r
                    uputsnl(s);\r
-             } else {\r
-                   // <I2c Address> <Read:0> <RegAddress>\r
+             } else if (Command[0] == 0x5){\r
+                   // <I2c Address> <Read:5> <RegAddress>\r
                   Command[0] = 0x50; // read\r
                   Command[1] = (Command[1]<<2) & 0xff;\r
-                  sprintf(s,"Status:0x%x   | Send to reg:  0x%x",I2C_Address, Command[1]);\r
+                  sprintf(s,"Addr:0x%x   | Send to addr:  0x%x",I2C_Address, Command[1]);\r
                   uputsnl(s);\r
 \r
                   twi_writeTo(I2C_Address, Command,2,1,true);\r
                    twi_readFrom(I2C_Address, &ReadReg, 3, true);\r
                   uint16_t Read = ReadReg[1]<<8 | ReadReg[2];\r
-                  sprintf(s,"Status: 0x%x  | Read result: D[15:8] 0x%x     D[7:0] 0x%x",ReadReg[0], ReadReg[1],ReadReg[2]);\r
+                  sprintf(s,"Status: 0x%x  | Read result: D[15:8] 0x%x     D[7:0] 0x%x   (reg: 0x%x, addr: 0x%x)",ReadReg[0], ReadReg[1],ReadReg[2],Command[1]>>2,Command[1]);\r
                   uputsnl(s);\r
+             } else if (Command[0] == 0xE){\r
+                   // <I2c Address> <Store:E>\r
+                  Command[0] = 0xE0; // read\r
+                  sprintf(s,"Store volatile memory in non-volatile.");\r
+                  uputsnl(s);\r
+                  twi_writeTo(I2C_Address, Command,1,1,true);\r
              }\r
              \r
              \r