mirror of https://github.com/arendst/Tasmota.git
Fix DS18x20 driver
This commit is contained in:
parent
643d3d0b69
commit
df34417861
|
@ -126,6 +126,8 @@ void OneWireWriteBit(uint8_t v)
|
||||||
delayMicroseconds(delay_high[v]);
|
delayMicroseconds(delay_high[v]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Fails for reasons unknown to me
|
||||||
uint8_t OneWireReadBit(void)
|
uint8_t OneWireReadBit(void)
|
||||||
{
|
{
|
||||||
if (!ds18x20_dual_mode) {
|
if (!ds18x20_dual_mode) {
|
||||||
|
@ -143,6 +145,35 @@ uint8_t OneWireReadBit(void)
|
||||||
delayMicroseconds(53);
|
delayMicroseconds(53);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
// Works fine in contrast to above. Why?
|
||||||
|
void OneWireReadBit1(void)
|
||||||
|
{
|
||||||
|
pinMode(ds18x20_pin, OUTPUT);
|
||||||
|
digitalWrite(ds18x20_pin, LOW);
|
||||||
|
delayMicroseconds(3);
|
||||||
|
pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); // SetOption74 - Enable internal pullup for single DS18x20 sensor
|
||||||
|
}
|
||||||
|
|
||||||
|
void OneWireReadBit2(void)
|
||||||
|
{
|
||||||
|
digitalWrite(ds18x20_pin_out, LOW);
|
||||||
|
delayMicroseconds(3);
|
||||||
|
digitalWrite(ds18x20_pin_out, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t OneWireReadBit(void)
|
||||||
|
{
|
||||||
|
if (!ds18x20_dual_mode) {
|
||||||
|
OneWireReadBit1();
|
||||||
|
} else {
|
||||||
|
OneWireReadBit2();
|
||||||
|
}
|
||||||
|
delayMicroseconds(10);
|
||||||
|
uint8_t r = digitalRead(ds18x20_pin);
|
||||||
|
delayMicroseconds(53);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -284,6 +315,7 @@ void Ds18x20Init(void)
|
||||||
uint64_t ids[DS18X20_MAX_SENSORS];
|
uint64_t ids[DS18X20_MAX_SENSORS];
|
||||||
|
|
||||||
ds18x20_pin = pin[GPIO_DSB];
|
ds18x20_pin = pin[GPIO_DSB];
|
||||||
|
|
||||||
if (pin[GPIO_DSB_OUT] < 99) {
|
if (pin[GPIO_DSB_OUT] < 99) {
|
||||||
ds18x20_pin_out = pin[GPIO_DSB_OUT];
|
ds18x20_pin_out = pin[GPIO_DSB_OUT];
|
||||||
ds18x20_dual_mode = true; // Dual pins mode as used by Shelly
|
ds18x20_dual_mode = true; // Dual pins mode as used by Shelly
|
||||||
|
@ -419,6 +451,8 @@ void Ds18x20Name(uint8_t sensor)
|
||||||
|
|
||||||
void Ds18x20EverySecond(void)
|
void Ds18x20EverySecond(void)
|
||||||
{
|
{
|
||||||
|
if (!ds18x20_sensors) { return; }
|
||||||
|
|
||||||
#ifdef W1_PARASITE_POWER
|
#ifdef W1_PARASITE_POWER
|
||||||
// skip access if there is still an eeprom write ongoing
|
// skip access if there is still an eeprom write ongoing
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
|
Loading…
Reference in New Issue