Open drain output question

11 Nov 2009

I would like to interface with some 5V devices and having the digital outputs work in open drain mode would do the trick.

Is there anyway to accomplish this?

Thanks,

Terry

11 Nov 2009 . Edited: 11 Nov 2009

Hi Terry,

Terry Gunnell wrote:
I would like to interface with some 5V devices and having the digital outputs work in open drain mode would do the trick. Is there anyway to accomplish this?

Good question. I'd never looked, but it appears the LPC1768 supports this; see chapter 8.4 in the LPC1768 manual (http://mbed.org/nxp/lpc1768/technical-reference/).  The raw registers that control these functions are therefore LPC_PINCON->PINMODE_OD0 - LPC_PINCON->PINMODE_OD4.

We should be able to add this functionality to the mbed DigitalOut library too (something like pin.mode(OpenDrain)), so i'll put it on the list.

As an aside, (if i'm thinking straight), you should be able to hack a similar effect using DigitalInOut i.e. set the output to 0, and then switch the pin by switching between an input (high) or output (low).

#include "mbed.h"

DigitalInOut pin(p5);

int main() {
    pin.output();
    pin = 0; // setup output as low
    while(1) {
        pin.input(); // high
        wait(0.25);
        pin.output(); // low
        wait(0.25);
    }
}

This might be a quick way to test out the ideas.

Simon

17 Nov 2009

Thanks Simon.

The pin.mode would be great!! That would be a nice addition to the DigitalInOut.

Terry

24 Apr 2011

DId this ever get implemented? It would be really handy for what I am working on right now.

24 Apr 2011

Hi Austin,

Yep, see mode() under /handbook/DigitalInOut. You should be able to do:

#include "mbed.h"

DigitalInOut pin(p5);

int main() {
    pin.mode(OpenDrain);
}

(although for some reason, it only seems to have been added to DigitalInOut, not DigitalOut. I'll make a note to get it added to DigitalOut too)

Hope that gives you what you want.

Simon

24 Apr 2011

Thanks for the quick answer - I think I can make this work. I'm trying to drive a switch matrix and need to isolate the scan outputs. I assume this will still work on pins that are part of a BusOut(...).

24 Apr 2011

Yep,

#include "mbed.h"

BusInOut pins(p5, p6);

int main() {
    pins.mode(OpenDrain);
}

Simon

24 Apr 2011

Excellent! Thanks for the quick response!

28 Jul 2011

That functionality would also be really useful on the TextLCD Library too. I think I'm right in saying that it currently uses the BusOut function.

11 Jun 2012

Hello,

I have also a problem with OpenDrain output. My codes are as below.

I have two buses (cRowBus and cColBus). I made them opendrain output. p29 didn't work, when I tried the first code. (I measure 111101 on cColBus pins, when I write to bus as cColBus.write(63); (111111). p29 was always zero.) I tryed this two codes on two mbed. Both of them were same. After, I tried the second code. (I just canceled cRowBus). It works fine. Why does this happen?

Thanks,

Selim.

1. code: 

#include "mbed.h"

BusInOut cRowBus(p5, p8, p10, p6, p9, p7);      
BusInOut cColBus(p25, p26, p27, p28, p29, p30); 
unsigned char x;
main(){
    cColBus.mode(OpenDrain);
    cColBus.output();
    cRowBus.mode(OpenDrain);
    cRowBus.output();
    while(1) {
        cColBus.write(63);
        wait_ms(100);
        cColBus.write(0);
        wait_ms(100);
    }
}


2. code :

#include "mbed.h"

//BusInOut cRowBus(p5, p8, p10, p6, p9, p7);      
BusInOut cColBus(p25, p26, p27, p28, p29, p30); 
unsigned char x;
main(){
    cColBus.mode(OpenDrain);
    cColBus.output();
  //  cRowBus.mode(OpenDrain);
  // cRowBus.output();
    while(1) {
        cColBus.write(63);
        wait_ms(100);
        cColBus.write(0);
        wait_ms(100);
    }
}
11 Jun 2012

Which mbed are you using?

Lerche

11 Jun 2012

Dear Christian,

I am using lpc1768 model.

Selim.

Christian Lerche wrote:

Which mbed are you using?

Lerche

12 Jun 2012

Can anyone try these codes on own mbed 1768 board for me?

02 Nov 2012

OpenDrain and pull modes have been added to the *In and *InOut, but they are also needed for an *Out(put). Open drain is an output feature only. To make things worse: sometimes you need both the "pull up" and "open drain" together as output (creating a weak one that can be pulled to zero elsewhere without creating a short circuit). It may be possible to implement it with two successive calls to mode().

#include "mbed.h"

DigitalOut pin(p5);

int main() {
    pin.mode(OpenDrain);
    pin.mode(PullUp);
}
14 Feb 2017

Hello, I know this is 4 years later but I believe that pin 29 is used as an input for RF signal that you cannot use it as a GPIO, But thanks to you I know that you can use pin 9, 10 and 30. Thank you, Kangpow