0

I'm using the gpio_get_level function documented here, which states that it returns a 0 or 1 depending on the value. What is the value if this function is called during a rising or a falling edge? Or can it never happen because of timing?

I tried to find this information in the datasheet but I couldn't find any information on this.

kovac
  • 343
  • 1
  • 8

2 Answers2

2

Well, a bit can't have a value of anything other than 0 or 1, so you'll read one or the other of those values. Exactly which one, if the voltage at the input is below VIH_min (75% of VCC: see datasheet at your link) and above VIL_max (25% of VCC) is undefined and not deterministic.

The GPIO level is sampled at discrete time points, determined by the GPIO peripheral's clock (usually derived from a main platform clock in an SoC), but it's usually not necessary to synchronize an input signal to that clock.

TypeIA
  • 2,232
  • 1
  • 12
  • 19
1

A digital input always reads as 0 or 1.

When the voltage is below VIL = 25 % of the supply voltage, the value is guaranteed to be 0.
When the voltage is above VIH = 75 % of the supply voltage, the value is guaranteed to be 1.
In between, there is no guarantee. The actual switching threshold will be near VIO/2, but you might get a value that is either 0 or 1 or even oscillating between 0 and 1. (Schmitt-trigger inputs would have hysteresis to prevent oscillations, but the ESP2366 does not appear to have them.) In practice, your signal edges are probably fast enough so that you will not see oscillations.

ESP2866 VIL VIH

CL.
  • 18,161
  • 5
  • 40
  • 67