Skip to content

Commit 5ba77db

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 3b1aa42 commit 5ba77db

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/driver/drv_ds1820_simple.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,17 @@ static int OWReset(int Pin)
6666
{
6767
int result;
6868

69-
vTaskSuspendAll();
69+
noInterrupts();
7070

7171
//HAL_Delay_us(OWtimeG);
7272
HAL_PIN_Setup_Output(Pin);
7373
HAL_PIN_SetOutputValue(Pin, 0); // Drives DQ low
7474
HAL_Delay_us(OWtimeH);
75-
HAL_PIN_SetOutputValue(Pin, 1); // Releases the bus
75+
HAL_PIN_Setup_Input_Pullup(Pin); // Releases the bus
7676
HAL_Delay_us(OWtimeI);
77-
HAL_PIN_Setup_Input_Pullup(Pin);
7877
result = HAL_PIN_ReadDigitalInput(Pin) ^ 0x01; // Sample for presence pulse from slave
7978

80-
xTaskResumeAll();
79+
interrupts();
8180

8281
HAL_Delay_us(OWtimeJ); // Complete the reset sequence recovery
8382
return result; // Return sample presence pulse result
@@ -121,11 +120,11 @@ static int OWReadBit(int Pin)
121120

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

0 commit comments

Comments
 (0)