Left here for archival purposes.

User avatar
By nickandrew
#30452 I'm trying to get a DS18B20 temp sensor working. Or rather, I have got it working with some workarounds. First, the 20150704 firmware has an error in onewire_search

Next, onewire_select() and onewire_skip() call onewire_write with the 3rd argument (power) set to zero, i.e.

Code: Select allvoid onewire_skip(uint8_t pin)
{
    onewire_write(pin, 0xCC, 0);           // Skip ROM
}


I noticed on my logic analyser, the output pin goes low at this point, which I believe it should not do. I believe the intent is for the pin to be tri-stated (high impedance) and the external resistor pulls up the pin to 3v3.

Looking at the code for onewire_write() ...

Code: Select all  if ( !power) {
    noInterrupts();
    DIRECT_MODE_INPUT(pin);
    DIRECT_WRITE_LOW(pin);
    interrupts();
  }


There seems to be a problem here. DIRECT_MODE_INPUT is defined as
Code: Select allGPIO_DIS_OUTPUT(pin_num[pin])
which disables output for the pin. But DIRECT_WRITE_LOW calls GPIO_OUTPUT_SET which re-enables output!

When I worked around the problem by calling onewire_write() myself with power = 1, the pin output anomaly vanished and my temp sensor worked.