Skip to content

Commit ded3289

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: openshwprojects#1582
1 parent 633f6b8 commit ded3289

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

sdk/OpenW600

src/driver/drv_ds1820_simple.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,17 @@ static int OWReset(int Pin)
6363
{
6464
int result;
6565

66-
vTaskSuspendAll();
66+
noInterrupts();
6767

6868
//HAL_Delay_us(OWtimeG);
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

77-
xTaskResumeAll();
76+
interrupts();
7877

7978
HAL_Delay_us(OWtimeJ); // Complete the reset sequence recovery
8079
return result; // Return sample presence pulse result
@@ -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)