Nie działą dalej:(. Wyraźnie brakuje prądu podczas konwersji temperatury i wstawia wartość domyślną. Znalazłem jeszcze w dokumentacji coś takiego:
However, when the DS18B20 is performing
temperature conversions or copying data from the scratchpad memory to EEPROM, the operating current
can be as high as 1.5mA. This current can cause an unacceptable voltage drop across the weak 1-Wire
pullup resistor and is more current than can be supplied by CPP. To assure that the DS18B20 has sufficient
supply current, it is necessary to provide a strong pullup on the 1-Wire bus whenever temperature
conversions are taking place or data is being copied from the scratchpad to EEPROM. This can be
accomplished by using a MOSFET to pull the bus directly to the rail as shown in Figure 4. The 1-Wire
bus must be switched to the strong pullup within 10μs (max) after a Convert T [44h] or Copy Scratchpad
[48h] command is issued, and the bus must be held high by the pullup for the duration of the conversion
(tCONV) or data transfer (tWR = 10ms). No other activity can take place on the 1-Wire bus while the pullup
is enabled.
Ja to rozumiem tak:
po komendzie 44 ustawić magistralę 10us najpuźniej na +5V i trzymać tak 750us..
Mój kod dokładnie to robi i nic. Ale jakby ktoś spojrzał bo po dłuższym czasie wpatrywania się w to samo ślepy człowiek się robi. Co do kolejności to wydaje się logiczna najpierw ustawić Hi, a potem podciągnąć napięcie, bo jakby odwrotnie zrobić to dallas mógłby dostawać ujemny ping. Kod:
therm_reset();
//therm_write_byte(THERM_CMD_READROM);
therm_write_byte(THERM_CMD_SKIPROM);
therm_write_byte(THERM_CMD_CONVERTTEMP);
//Wait until conversion is complete
//while(!therm_read_bit());
THERM_HIGH();
THERM_OUTPUT_MODE();
therm_delay(us(750));
//Reset, skip ROM and send command to read Scratchpad
therm_reset();
therm_write_byte(THERM_CMD_SKIPROM);
therm_write_byte(THERM_CMD_RSCRATCHPAD);
//Read Scratchpad (only 2 first bytes)
temperature = therm_read_byte();
temperature += (therm_read_byte()<<8);
therm_reset();
jeszcze to dorzuce, ale tutaj raczej się nie pomyliłem:
/* Thermometer Connections */
#define THERM_PORT PORTB
#define THERM_DDR DDRB
#define THERM_PIN PINB
#define THERM_DQ PB0
/* 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)