Report
8 months, 1 week ago.

DigitalIn ve DigitalOut modes

Hello, I've noticed that DigitalIn object has mode member function and it has three options:

void mbed::DigitalIn::mode ( PinMode pull ) inline Set the input pin mode

Parameters pull PullUp, PullDown, PullNone, OpenDrain

As far as i know OpenDrain is only an output option. I couldn't see the mode function for the DigitalOut object. Is there a documentation error or does it reflect the real situation here?

Comment on this question

1 Answer

8 months, 1 week ago.

Ultimately this hits the hardware of the microcontroller you're using. The top level mbed API's usually only implement a common subset of possible configurations available in the hardware. But you can always go down to the lower layers directly. For example with ST parts you should be able to do:

#include "hal/pinmap.h"

const PinName kPinOut = PA_1;
DigitalOut out(kPinOut);

pin_mode(kPinOut, PullUp);

Possible pin modes are:

typedef enum {
    PullNone          = 0,
    PullUp            = 1,
    PullDown          = 2,
    OpenDrainPullUp   = 3,
    OpenDrainNoPull   = 4,
    OpenDrainPullDown = 5,
    PushPullNoPull    = PullNone,
    PushPullPullUp    = PullUp,
    PushPullPullDown  = PullDown,
    OpenDrain         = OpenDrainPullUp,
    PullDefault       = PullNone
} PinMode;

Obviously this might vary based on your target. For example, I've used this to disable the tx and rx pins out of a uart (which normally rest at 3.3V) while leaving the uart peripheral initialized. Do each of these modes work with DigitalOut object? I'm not 100% sure, but it should only take a second to verify.


To post an answer, please log in.