Monday, February 2, 2015

Why Arduino Mega?

I have a spare Arduino Mega 1280. I bought it years ago, only to complete my collection of Arduino boards. I started the current project only to have it doing more than blinking a LED. And I found some interesting features.

First, it has lots of directly addressable pins... grouped together. For example, to set to "high" the pins marked "analog pins 0 to 7" as GPIO (digital pins), it is sufficient a single instruction:
PORTF = 0xff;
It is also convenient for setting more than one pin in a single instruction:
PORTF &= 0x3c;
More info on Port Manipulation.


Summary on the Arduino Mega boards (1280 and 2560):
  • PORTF: 8 in-line pins, west side ("analog pins 0 to 7")
  • PORTK: 8 in-line pins, west side ("analog pins 8 to 15")
  • PORTA: 8 pins (two adjacent rows of 4 pins), south side ("digital pins 22 to 29")
  • PORTC: 8 pins (two adjacent rows of 4 pins), south side ("digital pins 30 to 37")
  • PORTL: 8 pins (two adjacent rows of 4 pins), south side ("digital pins 42 to 49")
  • note also the blocks of 4 adjacent pins for PORTB, PORTH, PORTD.
If you don't need analog pins, you can fully use PORTF and PORTK to read/write up to eight pins at a time.

If you don't need external RAM/SRAM, you can fully use PORTA and PORTC.

If you don't use weird things like external interrupts, you can fully use PORTL.

Yeah, five blocks of 8 pins each. Things like:
if(PINK) call_a_function();
"if any input pin of PORTK is on level high, then call a function".

Just forget the digitalRead/digitalWrite stuff.

Just don't forget to assign the appropriate data direction register in the setup() phase.
DDRF = 0xff;    // declare eight output pins
PORTF = 0x1f;   // output 3 low and 5 high pins

No comments:

Post a Comment