Estou a tentar fazer um termómetro com um Atmega88. Tenho um DS18B20 que comprei e já vinha com um cabo. No entanto não estou a conseguir comunicar com ele. Encontrei várias bibliotecas e escolhi uma que me pareceu boa.
Ainda não detectei o problema ao certo mas sei que ele não consegue ler as temperaturas e logo no inicio, quando faço reset ao sensor tenho sempre uma resposta que penso ser negativa segundo a biblioteca.
Fica aqui o código da função reset:
uint8_t therm_reset()
{
uint8_t i;
//Pull line low and wait for 480uS
THERM_LOW();
THERM_OUTPUT_MODE();
therm_delay(us(480));
//Release line and wait for 60uS
THERM_INPUT_MODE();
therm_delay(us(60));
//Store line value and wait until the completion of 480uS period
i=(THERM_PIN & (1<<THERM_DQ));
therm_delay(us(420));
//Return the value read from the presence pulse (0=OK, 1=WRONG)
return i;
}
Os defines são:
#define THERM_PORT PORTC
#define THERM_DDR DDRC
#define THERM_PIN PINC
#define THERM_DQ PC2
/* Utils */
#define THERM_INPUT_MODE() THERM_DDR&=~(1<<THERM_DQ)
#define THERM_OUTPUT_MODE() THERM_DDR|=(1<<THERM_DQ)
#define THERM_LOW() THERM_PORT&=~(1<<THERM_DQ)
#define THERM_HIGH() THERM_PORT|=(1<<THERM_DQ)
/* list of these commands translated into C defines:*/
#define THERM_CMD_CONVERTTEMP 0x44
#define THERM_CMD_RSCRATCHPAD 0xbe
#define THERM_CMD_WSCRATCHPAD 0x4e
#define THERM_CMD_CPYSCRATCHPAD 0x48
#define THERM_CMD_RECEEPROM 0xb8
#define THERM_CMD_RPWRSUPPLY 0xb4
#define THERM_CMD_SEARCHROM 0xf0
#define THERM_CMD_READROM 0x33
#define THERM_CMD_MATCHROM 0x55
#define THERM_CMD_SKIPROM 0xcc
#define THERM_CMD_ALARMSEARCH 0xec
Quando imprimo o caracter "i" dá-me sempre 1, ou seja ou sensor não foi iniciado devidamente.