As mentioned in Arduino Cook Book (chapter 18: Using the Controller Chip Hardware,
18.11 Setting Digital Pins Quickly), Arduino digitalWrite provides a safe and easy-to-use method of setting and clearing pins, but it is more than 30 times slower than directly accessing the controller hardware. And using bitSet and bitClear with the following codes were compiled successfully under Arduino Uno (I modified the origin code and test it).
const int sendPin = 2;
// PORTD is defined as the register of digital pins from 0 to 7
And the problem is that “PORTD” is not defined in Arduino Due, can anybody who is familiar with Arduino Due give me some suggestions, what could be done to achieve the same target that is able to set or clear digital pins much faster than enabled by the Arduino digital Write command.
The definitions of bitSet and bitClear are as following in Arduino.h
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
I would like to reach as fast as possible, typ. 100~250 ns delay to reach HIGH and LOW as square wave signals for controlling of high speed mux. The Due runs at 84MHz, and the SPI clock pin had been tested with 11.9 ns duration square wave. Is SPI clock pin the only pin to have the highest speed or not?
Please feel free to give any suggestion.
I hope that my problem is explained well, and feel free to ask me, if you have any doubts.