DigitalInOut and PullUp mode

17 Sep 2010

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.

 

17 Sep 2010

Hmm. I've used a 1-wire bus to interface an n64 contoller. I could be mistaken, but for a 1-wire interface, you should use the open-drain mode with an external pull-up. I've never had to switch input/output modes. Pin.read() and pin.write seems to work without doing pin.output or pin.input. Also, I am not sure if the -> notation works for calling functions..? I've never seen it used like that..

 

17 Sep 2010

Thanks for the response. The '->' is just because I've used a pointer to a DigitalInOut. pin->input() is the same as (*pin).input(). It's perfectly valid C/C++ syntax.

With the 1-wire bus. How did it work not having to use the input() and output() functions. The mbed handbook claims that pin.read() does different things depending which mode your in. I.e. if in output mode it gives the state last assigned to the pin from a write() method and if in input mode it gives the state being supplied to the pin.

I'll have a play around with the open-drain mode though, thanks for that.

17 Sep 2010

Hmm, the mbed crashes and does it's little LED dance when I try using OpenDrain.

17 Sep 2010

Hmm.. Unless something was changed in the latest mbed library update, I am not sure.. But it did work.. I'll look into my code when I have some time.

18 Sep 2010 . Edited: 18 Sep 2010

Hi T L,

The LED dance (Blue Lights Of Death) when trying to select Open Drain mode suggests it is not supported, which means you are probably using the original LPC2368 version of mbed. Unfortunately, the LPC2368 chip doesn't support open drain, and we introduced the OpenDrain option for the LPC1768. Hopefully your project won't need it.

I'll file the example you gave as a potential bug, and we'll investigate. In the mean time to get you going, perhaps you could try:

  • Using an external pull-up, or
  • Wiring two pins together, as you mention

It'd be good to hear if you can get something working.

Simon