1

What is the fastest way to read a digital pin status in an Arduino Due? Is it possible to achieve speed in the Nanosecond area?

With which type of code I can achieve this?

Edit: This question is not a duplicate please see my comment.

asked Mar 6, 2017 at 12:18
8
  • 1
    Yes, write to or read from the correct GPIO / PORT registers directly. Best case this needs only a few CPU cycles to read, i.e. a few nanoseconds. The processing time after that unknown, dependent on what you want to do with the read out data. Duplicate of arduino.stackexchange.com/questions/9117/…. Also read forum.arduino.cc/index.php?topic=260731.0 . Commented Mar 6, 2017 at 12:27
  • 1
    Possible duplicate of SAM3X8E (Arduino Due) Pin IO registers Commented Mar 6, 2017 at 19:31
  • 1
    No it is not a duplicate. There you will find the answer how to set a digital pin as an output, but NOT how to set it as in input and read its pin state. Or atleast it is not explained detailed enough. Also you will not find the appropiate answer to the question "the fastest" but only sadly an alternative to the digitalWrite. You will not find any type of code example to set a pin as an input and to read from it, which actually for beginners like me would be very vital, if you would not forget that espiacially the "unnormal" register commands are very cryptic for a beginner. Commented Mar 6, 2017 at 19:50
  • ns? no. us? yeah. Commented Mar 6, 2017 at 20:39
  • The OneWire library uses it: github.com/PaulStoffregen/OneWire/blob/master/OneWire.h Commented Mar 6, 2017 at 22:59

2 Answers 2

2

If the pin is declared as input, let's say pin 13:

uint32_t pin_status;
pin_status = PIOB->PIO_PDSR & PIO_PDSR_P27;

If the pin is declared as output, let's say pin 13:

uint32_t pin_status;
pin_status = PIOB->PIO_ODSR & PIO_ODSR_P27;
dda
1,5951 gold badge12 silver badges17 bronze badges
answered Jul 6, 2017 at 11:59
0

Read the In out data register would be the fastest.

answered Jul 6, 2017 at 12:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.