You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It was found that Ultrasonic HC-SR04 set eith Echo pin = 13 always returns 0 cm disatance.
The problem is in the old code of pulseIn(), see Arch/Esp8266/Core/Digital.cpp.
Now GPIO_IN register is read as a whole 32bit value, *portInputRegister(port) returns 32bit value.
But pin's respective variables bit and stateMask are still defined as uint8_t, as they were when GPIO_IN was processed by 8bit parts. Therefore bit and stateMask will be 0 always for pins >=8 and will never match the value read from the register.
So, the variable needs a correction:
--- a/Sming/Arch/Esp8266/Core/Digital.cpp+++ b/Sming/Arch/Esp8266/Core/Digital.cpp@@ -141,9 +141,9 @@ unsigned long pulseIn(uint16_t pin, uint8_t state, unsigned long timeout)
// cache the port and bit of the pin in order to speed up the
// pulse width measuring loop and achieve finer resolution. calling
// digitalRead() instead yields much coarser resolution.
- uint8_t bit = digitalPinToBitMask(pin);+ uint32_t bit = digitalPinToBitMask(pin);
// uint8_t port = digitalPinToPort(pin); // Does nothing in Sming, comment-out to prevent compiler warning
- uint8_t stateMask = (state ? bit : 0);+ uint32_t stateMask = (state ? bit : 0);
unsigned long width = 0; // keep initialization out of time critical area
// convert the timeout from microseconds to a number of times through
The text was updated successfully, but these errors were encountered:
@alexdz18 Thanks for pointing this out. Can you please open a PR with the change to receive the deserved credit for it? Take a look at the contributing guide if you need some guidance.
It was found that Ultrasonic HC-SR04 set eith Echo pin = 13 always returns 0 cm disatance.
The problem is in the old code of pulseIn(), see Arch/Esp8266/Core/Digital.cpp.
Now GPIO_IN register is read as a whole 32bit value, *portInputRegister(port) returns 32bit value.
But pin's respective variables bit and stateMask are still defined as uint8_t, as they were when GPIO_IN was processed by 8bit parts. Therefore bit and stateMask will be 0 always for pins >=8 and will never match the value read from the register.
So, the variable needs a correction:
The text was updated successfully, but these errors were encountered: