Using digitalWriteFast on the Arduino Nano Every

Hello everyone,

I have been working on a design that uses the Arduino Nano and makes liberal use of the "digitalWriteFast" library. For those that don't know this library speeds up writing and reading digital pins by doing Port Manipulation and getting rid of some of the extra steps included in the standard digitalWrite/ digitalRead commands. I was very excited to find out about the Nano Every while working on this and bought a few to try and replace the Nano in my design and unfortunately the digitalWriteFast library does not appear to work with it.

My code is quite large and Im not sure that it will help in this case but here are the errors that I get when I try to compile for the Nano Every.

Arduino: 1.8.13 (Windows 10), TD: 1.53, Board: "Arduino Nano Every, None (ATMEGA4809)"

In file included from C:\Users\ile\Documents\Arduino\IDUM v2\IDUM_new_version_v.07\IDUM_new_version_v.07.ino:18:0:

C:\Users\ile\Documents\Arduino\IDUM v2\IDUM_new_version_v.07\a01Setup.ino: In function 'void setup()':

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:285:28: error: 'DDRD' was not declared in this scope

(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))

^

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:16:44: note: in definition of macro 'BIT_SET'

define BIT_SET(value, bit) ((value) |= (1UL << (bit)))

^~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:329:3: note: in expansion of macro 'BIT_WRITE'

BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \

^~~~~~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:329:14: note: in expansion of macro '__digitalPinToDDRReg'

BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \

^~~~~~~~~~~~~~~~~~~~

C:\Users\ile\Documents\Arduino\IDUM v2\IDUM_new_version_v.07\a01Setup.ino:5:3: note: in expansion of macro 'pinModeFast'

pinModeFast( loopLED, OUTPUT);

^~~~~~~~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:285:28: note: suggested alternative: 'VDD'

(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))

^

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:16:44: note: in definition of macro 'BIT_SET'

define BIT_SET(value, bit) ((value) |= (1UL << (bit)))

^~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:329:3: note: in expansion of macro 'BIT_WRITE'

BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \

^~~~~~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:329:14: note: in expansion of macro '__digitalPinToDDRReg'

BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \

^~~~~~~~~~~~~~~~~~~~

C:\Users\ile\Documents\Arduino\IDUM v2\IDUM_new_version_v.07\a01Setup.ino:5:3: note: in expansion of macro 'pinModeFast'

pinModeFast( loopLED, OUTPUT);

^~~~~~~~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:285:63: error: 'DDRB' was not declared in this scope

(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))

^

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:16:44: note: in definition of macro 'BIT_SET'

define BIT_SET(value, bit) ((value) |= (1UL << (bit)))

^~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:329:3: note: in expansion of macro 'BIT_WRITE'

BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \

^~~~~~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:329:14: note: in expansion of macro '__digitalPinToDDRReg'

BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \

^~~~~~~~~~~~~~~~~~~~

C:\Users\ile\Documents\Arduino\IDUM v2\IDUM_new_version_v.07\a01Setup.ino:5:3: note: in expansion of macro 'pinModeFast'

pinModeFast( loopLED, OUTPUT);

^~~~~~~~~~~

C:\Users\ile\Documents\Arduino\libraries\digitalwritefast/digitalWriteFast.h:285:63: note: suggested alternative: 'DD0'

(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))

^
.............................

There are a few pages of this, it is largely the same error over and over again, namely that the DDRB, DDRC and DDRD are not declared. I believe that the Nano Every is based on the same architecture as the Arduino Mega and I found another thread mentioning that there are some differences in how the Arduino Uno and Mega do port manipulation however the thread is almost 10 years old and many of the links are broken. Link is here: digitalWriteFast, digitalReadFast, pinModeFast etc - Bugs & Suggestions - Arduino Forum I can see from the Port Manipulation article on the Arduino site that these are references to the pin ports and Im guessing that these are called something else in the MCA used on the Nano Every Arduino Reference - Arduino Reference .

Im happy to modify the library code, if anyone could point me in the direction what these variables/ registers should be replaced with I would greatly appreciate it.

Thank you for reading!

Try this one: Duino-hacks/fastdigitalIO.h at master · WestfW/Duino-hacks · GitHub
Um. It doesn't do pinModeFast()

I think DrAzzy has added a version to his megaTinyCore as well; perhaps a better tested and more complete version; it should probably work on Every as well.

mysticcircuits, why do you need a fast digitalWriteFast ? Are those microseconds important or do you think that fast is better ?

The Nano Every uses the ATMega4809. It has hardware that can do more, but also the software is a modern way. Arduino has made a separate branch for them, the megaAVR branch.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.