Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digitalWrite() backwards compatibility problem #86

Open
benwillcocks opened this issue Nov 4, 2020 · 0 comments
Open

digitalWrite() backwards compatibility problem #86

benwillcocks opened this issue Nov 4, 2020 · 0 comments

Comments

@benwillcocks
Copy link

Line 164 of wiring_digital.c has the comment "old implementation has side effect when pin set as input - pull up is enabled if this function is called. Should we purposely implement this side effect?". Actually, a more important feature of the old implementation of digitalWrite(), which is missing from the new implementation, is that it can be used to set the output register whilst the pin is configured as an input. Here are two situations where this is useful:
1] if a pin is used for bidirectional communication, it can be necessary to change direction from input to output without changing the state of the pin. To achieve this one needs to read the input, set the output register accordingly, and then make the pin an output.
2] if multiple pins (not necessarily on the same port) are commoned for extra drive strength, then one must be careful to avoid the outputs fighting one another. When changing the state it is necessary to make all the pins inputs, then change the output registers, then make all the pins outputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant