I am working since a while on I2C interface with The infineon's magnetic sensor.
I make my own program to get the register values and calculate the temperature, Magnetic flux etc. The problem is that it is having some inappropriate values. Then I checked online and found the implementation on the following website. there is also code available for this ...
My value for temperature and the one provided in the link are the same. That means both are wrong.
I am uploading the code which I wrote.. Any idea what is going wrong here?
#include <Wire.h>
#define device 0x5E
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Reseting the sensor....."
"And coping values from read reg to write reg");
reset_sensor(0xFF);
reset_sensor(0x00);
delay(100);
byte data[10];
TLVburst_read(data);
//check the status of bits 4:3 in reg 7
byte backup_1;
backup_1=(data[7]<<3);
backup_1=backup_1>>6;
byte backup_2=data[9]<<3;
backup_2=backup_2>>3;
byte Write_data[4];
Write_data[0]=0x00;
Write_data[1]=(0b000<<5)+(backup_1<<3)+0b101;
Write_data[2]=0x00;
Write_data[3]=(0b010<<5)+backup_2;
//Serial.println(Write_data[1], BIN);
int i=sizeof(Write_data);
Write_TLV(Write_data,i);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("New Readings................");
delay(1000);
byte data[10];
TLVburst_read(data);
int LSB=((data[3]>>7)&(1))*(-2048)+((data[3]>>6)&(1))*1024+((data[3]>>5)&(1))*512+((data[3]>>4)&(1))*256+((data[6]>>7)&(1))*128+((data[6]>>6)&(1))*64+((data[6]>>5)&(1))*32+((data[6]>>4)&(1))*16+((data[6]>>3)&(1))*8+
((data[6]>>2)&(1))*4+((data[6]>>1)&(1))*2+((data[6]&(1))*1);
int temprature=(LSB-340)*(1.1);
Serial.println("Temprature");
Serial.println(temprature);
}
void TLVburst_read(byte data[]){
Wire.beginTransmission(device);
Wire.requestFrom(device, 10);
for (int i = 0; i <7; i++) {
data[i] = Wire.read();
Serial.println(data[i],HEX);
}
Wire.endTransmission(device);
}
void Write_TLV(byte data[],int j){
Wire.beginTransmission(device);
for (int i = 0; i <j; i++){
Wire.write(data[i]);
//Serial.println("Writing...");
//Serial.println(data[i],HEX);
}
Wire.endTransmission(device);
}
void reset_sensor(byte data){
Wire.beginTransmission(device);
Wire.write(data);
Wire.endTransmission(device);
}