david_prentice:
God gave you "numbered" pins like Digital#9 or Analog#3 to make shields work with different Arduino boards.
Yes, you can mix direct register statements with the Arduino code. But it obviously makes your sketch non-portable.
David, my goal is not to make the sketch portable.
david_prentice:
Writing to PORTD on an AVR will affect the whole 8-bit port. With a Due or Zero, you can set or clear multiple bits with a single statement VERY efficiently. Doing the same on a Mega is slower and non-atomic. The Xmega can write to its ports efficiently like the ARM.
Yes, that is exactly what I'm trying to achive - to affect the whole 8-bit port on Arduino Uno, and at least 8-bit portion on port on Arduion Due.
For now, my understanding is that there is no way to affect the whole port on Arduion Due, but rather is has to be done is small steps, one at a time - by setting bit by bit of the whole port?
Am I right on this part?
Here is the code I wrote to set up 8-bit portion of PORT D on Arduino Due:
void setup() {
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
pinMode(27, OUTPUT);
pinMode(28, OUTPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
pinMode(29, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
for (float i=0; i<5000001; i++)
{
REG_PIOD_SODR = 0x1 << 0;
REG_PIOD_SODR = 0x1 << 1;
REG_PIOD_SODR = 0x1 << 2;
REG_PIOD_SODR = 0x1 << 3;
REG_PIOD_SODR = 0x1 << 4;
REG_PIOD_SODR = 0x1 << 5;
REG_PIOD_SODR = 0x1 << 6;
REG_PIOD_SODR = 0x1 << 7;
}
}
Do you agree that this is the only way to set up pins at port D on Arduino Due as a whole 8-bit?
david_prentice:
You can probably create some macros to access 8-bit portions of a 32-bit port. However, the Zero shield pins are not in convenient 8-bit order.
David.
I hope the Zero has comand to affect the whole port with one (1) single comand?