Un saludo a todos,
Recientemente empece a trabajar con un sensor de temperatura digital el LM92. Como posee un registro para interrupción, éste se configura con enviar una cadena de 16bits. El problema que tengo es que no se como enviar los 16bits ya que parece no soportar el valor en la rutina .write() y si la segmento en 2 conjuntos de 8bits parece que no funciona.
Mi código es el siguiente:
Reading LM92.
#include <Wire.h>
char lm92addr = 0x48; //A1 and A0 to GND #1001000
int val = 0x1900;
char buffer[2];
int tempcode;
float temp;
void setup()
{
Serial.begin(9600);
Wire.begin();
// Pag. 13 on Datasheet, the register is 16bits
// (temperature data is bit3 - bit15)
Wire.beginTransmission(lm92addr);
Wire.write(0x04); // Register address for configure T_LOW
Wire.write(0x18); // set value: 0001100000000000 T-Low 30ºC first 8Bit
Wire.write(0x00); // second 8Bit
// T_High
Wire.write(0x05); // Register address for configure T_High
Wire.write(0x19); // set value: 0001100110000000 T_High 33ºC
Wire.write(0x80);
Wire.endTransmission();
}
void loop()
{
Wire.requestFrom(lm92addr,2); // Se solicitan los dos Bytes
if (Wire.available())
{
for(int i=0; i<2; i++)
{
buffer[i]= Wire.read();
}
tempcode= ((buffer[0] << 8) + buffer[1]) >>3;
temp = tempcode * 0.0625;
Serial.print("t = ");
Serial.print(temp);
Serial.print(" C");
Serial.println();
}
delay(500);
}
Ya no se me ocurre otro metodo de configurar mi sensor :~ ya que obtener los datos de temperatura no he tenido ningún problema.
Gracias adelatadas. XD