Hi,
I need to read data from MLX90615. It is a temperature sensor which follows I2C to read data. I got a sample code for this which is given below.
float receiveTemperature(int Temperature_type) {
int dev = (0x5B << 1); // 5B is the device address
char dataLow = 0; // initially setting data low as zero
char dataHigh = 0; // initially setting data high as zero
char pec = 0;
float celcius = 0.0;
start(dev | I2C_WRITE); // start by sending device address
write(Temperature_type); // choosing ambient or object temperature
// read
restart(dev | I2C_READ); // restart
dataLow = read(false); // reading lower bytes
dataHigh = read(false); // reading higher bytes
pec = read(true); // reading packet error code
stop();
// This combines high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double resolutionFactor = 0.02; // resolution factor of the MLX90614
double temperature = 0x0000;
int frac; // data past the decimal point
temperature = (double)(((dataHigh & 0x007F) << 8) | dataLow); // removes error bit of high byte by shifting and adds the low byte
temperature= (temperature * resolutionFactor) - 0.01; // multiplying temperature value with resolutionFactor
celcius = (float)(temperature- 273.15);
return celcius; // return the value of temperature in celcius
}
In this, how can I change the API to nRF TWI drivers? I know the question is so stupid. But as a new comer the nRF APIs seems to be tougher for me.