Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 6 months ago.
DigitalIn initial value
Hi team,
When pin 8 is open, the following program displays 1 then 0 when compiled with the latest (rev.63) mbed library. But the output should be 0 then 0 according to the DigitalIn handbook.
#include "mbed.h" DigitalIn digitalIn(p8); int main() { printf("%d\n", digitalIn.read()); printf("%d\n", digitalIn.read()); }
Any suggestions?
Hiroshi
2 Answers
11 years, 6 months ago.
Random idea, but default state of all pins is pull-up enabled. As soon as you make a DigitalIn object it will enable the pull-down, but it takes a very short amount of time to discharge the input capacitance when the pull-down is activated. If you immediatly read the input it might still be high.
11 years, 6 months ago.
Erik,
Thanks for the exlanation. If I put a very small delay, less than 1 us, the program displays as I expected.
BTW, this behavior seems to have been introduced since the r44 build, when the refactoringof the core library was made.
Hiroshi