LM92 I2C problema lettura temperatura
Buon giorno,
Mi potete aiutare alla programmazione? Uso un LM92 (sensore di temperatura) e un Stamp che ho fatto con un PIC 16F690.
Devo leggere un signal I2C della temperatura del LM92 con un oscillioscopio.
Non capisco perche quando faccio read_i2c(); e guardo sul oscillioscopio e mi da sempre una data FF, anche se disconnetto il mio print LM92.
Scusa se c'è dei commenti in francese
Mi potete aiutare alla programmazione? Uso un LM92 (sensore di temperatura) e un Stamp che ho fatto con un PIC 16F690.
Devo leggere un signal I2C della temperatura del LM92 con un oscillioscopio.
Non capisco perche quando faccio read_i2c(); e guardo sul oscillioscopio e mi da sempre una data FF, anche se disconnetto il mio print LM92.
Scusa se c'è dei commenti in francese
- Codice: Seleziona tutto
//---------------------------------------------------------------------
// Definitions & byte
//---------------------------------------------------------------------
#byte OSCCON = 0x8F
#define LM92_RD 0x91 // lm92 addresse de lecture
#define LM92_WR 0x90 // lm92 addresse d'écriture
#define LM92_TEMP_PTR 0x00 //adresse du registre pointer Read
//---------------------------------------------------------------------
// Variable Globale
//---------------------------------------------------------------------
int temp_msb , temp_lsb;
int val;
//---------------------------------------------------------------------
// Fonction
//---------------------------------------------------------------------
void LM92_RD_TEMP()
{
i2c_start(); // debut
i2c_write(LM92_WR); // adresse du LM92 en écriture
i2c_write(LM92_TEMP_PTR); // adresse du registre pointer
//i2c_start(); // re-start
i2c_write(LM92_RD); // adresse du LM92 en lecture
temp_msb = i2c_read(1); // stockage du msb temperature +ACK
temp_lsb = i2c_read(0); // stockage du Lsb sans ACK
i2c_stop(); // fin
}
//---------------------------------------------------------------------
// Programme principal
//---------------------------------------------------------------------
void main()
{
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128|RTCC_8_bit); //32.7 ms overflow
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
enable_interrupts(GLOBAL);
bit_set(OSCCON,4);
bit_set(OSCCON,5);
bit_set(OSCCON,6);
delay_ms(100);
while(TRUE)
{
LM92_RD_TEMP();
val = temp_msb;
val = val<<8;//prendre les premiers 8 bits
val = val +(temp_lsb&0b11111000);//faire un masque sans utilisé les 3 premiers bits
val = val>>3;// enlever les 3 premiers bits
val = val * 0.0625;
}
}