I can't seem to get the internal pull up resistors to work with pins that are being used via a DigitalInOut object. If you use the pin as an output and then switch it to an input then the value of the pin when you read is simply the last value you outputted and doesn't default to 1 (as it surely should?).
I have the following code and the pin value that gets printed back is 0. If the last thing you outputted was a 1 then it prints back a 1, so it's simply retaining the output state. Why doesn't calling pin->input() release the pin?
#include "mbed.h"
DigitalInOut *pin;
Serial pc(USBTX, USBRX);
int main() {
int bitVal;
pin = new DigitalInOut(p5);
pin->mode(PullUp);
pin->output();
pin->write(0);
pin->input();
bitVal = pin->read();
pc.printf("Pin value: %i\r\n", bitVal);
}
Moving the call to pin->mode(PullUp) to after the pin->input() call doesn't change the outcome.
I need this for a 1-wire bus. The only work around I can think is to feed the bus into two pins on the mbed and use one as an input and one as an output, but that's obviously pretty wasteful.
I can't seem to get the internal pull up resistors to work with pins that are being used via a DigitalInOut object. If you use the pin as an output and then switch it to an input then the value of the pin when you read is simply the last value you outputted and doesn't default to 1 (as it surely should?).
I have the following code and the pin value that gets printed back is 0. If the last thing you outputted was a 1 then it prints back a 1, so it's simply retaining the output state. Why doesn't calling pin->input() release the pin?
I need this for a 1-wire bus. The only work around I can think is to feed the bus into two pins on the mbed and use one as an input and one as an output, but that's obviously pretty wasteful.