Skip to content

Commit 240a95a

Browse files
committed
drv_ds1820_simple.c - fixed onewire protocol
* Do not use HAL_PIN_SetOutputValue() when reading sensor response - output must be open-drain. * Use Input_Pullup when reading sensor response instead. That allows to connect sensor w/o adding pullup resistor. * Fixed OWReadBit timing, read must be done within 15us, instead of after. Closes: #1582
1 parent 633f6b8 commit 240a95a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/driver/drv_ds1820_simple.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ static int OWReset(int Pin)
6969
HAL_PIN_Setup_Output(Pin);
7070
HAL_PIN_SetOutputValue(Pin, 0); // Drives DQ low
7171
HAL_Delay_us(OWtimeH);
72-
HAL_PIN_SetOutputValue(Pin, 1); // Releases the bus
72+
HAL_PIN_Setup_Input_Pullup(Pin); // Releases the bus
7373
HAL_Delay_us(OWtimeI);
74-
HAL_PIN_Setup_Input_Pullup(Pin);
7574
result = HAL_PIN_ReadDigitalInput(Pin) ^ 0x01; // Sample for presence pulse from slave
7675

7776
xTaskResumeAll();
@@ -118,11 +117,11 @@ static int OWReadBit(int Pin)
118117

119118
noInterrupts();
120119
HAL_PIN_Setup_Output(Pin);
121-
HAL_PIN_SetOutputValue(Pin, 0); // Drives DQ low
122-
HAL_Delay_us(OWtimeA);
123-
HAL_PIN_SetOutputValue(Pin, 1); // Releases the bus
124-
HAL_Delay_us(OWtimeE);
125-
HAL_PIN_Setup_Input_Pullup(Pin);
120+
HAL_PIN_SetOutputValue(Pin, 0); // Drives DQ low
121+
HAL_Delay_us(1); // give sensor time to react on start pulse
122+
HAL_PIN_Setup_Input_Pullup(Pin); // Release the bus
123+
HAL_Delay_us(OWtimeE); // give time for bus rise, if not pulled
124+
126125
result = HAL_PIN_ReadDigitalInput(Pin); // Sample for presence pulse from slave
127126
interrupts(); // hope for the best for the following timer and keep CRITICAL as short as possible
128127
HAL_Delay_us(OWtimeF); // Complete the time slot and 10us recovery

0 commit comments

Comments
 (0)