From ff8b06dc5a1f544c7ff3abd7b466421c0f8c4d27 Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Thu, 8 Feb 2018 14:08:17 +0100 Subject: [PATCH] Magn Sens: New commands for reading/writing/storing --- sensors/MagneticFieldSensor/main.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sensors/MagneticFieldSensor/main.c b/sensors/MagneticFieldSensor/main.c index f51c346..ee685c6 100644 --- a/sensors/MagneticFieldSensor/main.c +++ b/sensors/MagneticFieldSensor/main.c @@ -76,7 +76,7 @@ int main(void) uputsnl(s); } else if (mode != 0) { - + // CONFIG mode unsigned position = 0; char * ptr; ptr = strtok(uart_string," "); @@ -142,26 +142,32 @@ int main(void) - if (Command[0] == 1){ + if (Command[0] == 0x6){ Command[0] = 0x60; // write Command[3] = (Command[3]<<2) & 0xff; - // + // status2 = twi_writeTo(I2C_Address, Command, 4,1, true); twi_readFrom(I2C_Address, &status, 1, true); 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]); uputsnl(s); - } else { - // + } else if (Command[0] == 0x5){ + // Command[0] = 0x50; // read Command[1] = (Command[1]<<2) & 0xff; - sprintf(s,"Status:0x%x | Send to reg: 0x%x",I2C_Address, Command[1]); + sprintf(s,"Addr:0x%x | Send to addr: 0x%x",I2C_Address, Command[1]); uputsnl(s); twi_writeTo(I2C_Address, Command,2,1,true); twi_readFrom(I2C_Address, &ReadReg, 3, true); uint16_t Read = ReadReg[1]<<8 | ReadReg[2]; - sprintf(s,"Status: 0x%x | Read result: D[15:8] 0x%x D[7:0] 0x%x",ReadReg[0], ReadReg[1],ReadReg[2]); + 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]); uputsnl(s); + } else if (Command[0] == 0xE){ + // + Command[0] = 0xE0; // read + sprintf(s,"Store volatile memory in non-volatile."); + uputsnl(s); + twi_writeTo(I2C_Address, Command,1,1,true); } -- 2.43.0