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.
6 years, 7 months 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?
1 Answer
6 years, 7 months 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.