Go Down

Topic: Fast DigitalWrite for Arduino Due (Read 181 times) previous topic - next topic

randomvibe

Is there a method for increasing the speed of setting a digital pin to High or Low?  I tried the following on the Due unsuccessfully - unfortunately it was made for the 8-bit boards:

http://skpang.co.uk/blog/archives/323


MorganS

Why? Maybe if you described your actual problem or posted some code we could help with that.
GoForSmoke: "What GShield? You never mentioned a shield."

MarkT

#2
Apr 12, 2015, 12:18 am Last Edit: Apr 12, 2015, 12:18 am by MarkT
There are various threads on here for direct port manipulation on the Due - have
you searched for them?
[ I won't respond to messages, use the forum please ]

semipro

There are various threads on here for direct port manipulation on the Due - have
you searched for them?
One such thread is http://forum.arduino.cc/index.php?topic=129868.15.
Essentially you just have a pointer to a structure, which has to long members, one that clears and one that turns on the pin. Here is the quote of the post that shows how this works.
The other way of doing direct port manipulation looks like this:
Code: [Select]
PIOx->register=value;   
long r = PIOx->register;

where x is A,B,C or D and register is as in the data sheet

For example:
Code: [Select]

PIOB->PIO_SODR=1<<27; //lights the LED
PIOB->PIO_CODR=1<<27; //clears it
boolean p12=!!(PIOD->PIO_PDSR & (1<<8)); //read pin 12


I had a go at writing some digitalReadDirect/digitalWriteDirect functions but you might want to give them some more thorough testing as I only checked if it worked with the LED   :)

Code: [Select]

inline void digitalWriteDirect(int pin, boolean val){
  if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
  else    g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}

inline int digitalReadDirect(int pin){
  return !!(g_APinDescription[pin].pPort -> PIO_PDSR & g_APinDescription[pin].ulPin);
}

void setup() {               
  pinMode(13, OUTPUT);     
  pinMode(12, INPUT);     
  Serial.begin(9600);
}

void loop() {
  digitalWriteDirect(13, HIGH);   
  delay(1000);           
  digitalWriteDirect(13, LOW);   
  delay(1000);         
  Serial.println(digitalReadDirect(12));
}



Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy