0

I've been doing research for the last few hours trying to determine the mapping of physical pins to memory-mapped I/O registers for the Arduino Mega board (which is an ATmega 2560 R3).

Some of the registers used include CS11, DDB4, DDRA, DDRB, GICR, INT0, INT1, ISC00, ISC10, MCUCR, PA0, PB5, PB7, PD2, PD3, PIND, PORTA, PORTD, SPCR, SPDR, SPIF, SPSR, TCCR1B, and TCNT1. I can't figure out which pins these are and/or what they do.

Here is a diagram provided by the upstream example:

enter image description here

Unfortunately, I'm not very good at reading these diagrams so I'm doing my best.

How can I determine the mapping of these registers to physical ports on both the ATmega 32A, which is the board the example was originally written for, and the ATmega 2560 R3, which is the board I'm currently working with?

1

What is ATmega2560 R3? There is ATmega2560 MCU or Arduino Mega R3. do you want the mapping of pins of Arduino Mega or the pins of the ATmega2560 MCU.

The mapping of pins of the ATmega 2560 chip is in the datasheet.

The mapping of the Arduino Mega pins to ATmega2560 pins and registers is in the schema of the board or in the Arduino AVR boards package variants mega folder.

The link "Arduino's 2560 pin mapping" in your question shows the mapping too. Registers are PA, PB,... and every register covers to 8 pins with the 8 bits of the register. For example PB3 is pin 50 of the board.

| improve this answer | |
  • This is the exact board that I bought, and I'm looking for a reference on which pins on the board correspond with which registers exposed in the avr C library. The schema doesn't seem to list things like PORTA and so on that are referenced in the code I'm working from. – Naftuli Kay Feb 1 '19 at 17:08
  • it is an Arduino Mega clone. the link to schema is in answer. – Juraj Feb 1 '19 at 17:12
  • Because I'm porting code that I did not write. I need to understand what the code is actually doing before I can start porting it to my board. – Naftuli Kay Feb 1 '19 at 17:14
  • but the schema clearly shows the register to board pin mapping. and that is what you asked. and the link "Arduino's 2560 pin mapping" in your question shows it too – Juraj Feb 1 '19 at 17:21
  • I added something to the answer – Juraj Feb 1 '19 at 17:27
0

Atmega32A is a 44 pin TQFP part with 4 8-bit IO ports. It is kind of a crippled Atmega1284P. You may have an easier time just switching to a 1284P chip (also 44 pin TQFP) to take advantage of its 16K byte SRAM and 128K byte flash. There's an easy to use add-in to the Arduino IDE to use it. https://github.com/MCUdude/MightyCore I do a lot of 1284P designs and use it all the time.

Atmega2560 is 100 pin TQFP part with 10 8-bit and one 6-bit IO ports.

As your schematic only uses a few IO pins, the electrical connections will be simple - SPI for bootloading or downloading code - 2 pins for serial - 2 pins for other IO

If you look at the Arduino Mega2560 schematic, you can pick those out pretty readily. The rest you will have to tweak up in your code.

| improve this answer | |
  • 1
    he has a Mega. nothing special – Juraj Feb 1 '19 at 17:13
  • I'm hoping to start with the board that I have (mega 2550) and then use conditional compilation to support other boards. I'm having a hard time with the schematic, as it doesn't seem to list which registers map to which pins, e.g. what is PORTA and what is it mapped to in avr's C library and what does it do? Is there a reference I can look at to determine this? – Naftuli Kay Feb 1 '19 at 17:13
  • The IDE already does that mapping. For example, on '328P board, Port D is D7-D0, PORT B is D13 to D8 (upper two bits not used as IO), Port C 9 is D19 to D14. (upper two bit not used as IO). Used to be that you could look at pins_arduino.h (I think that's the name) in the IDE folders for a particular board and read the mapping from PINx/PORTx to the IO pins. I can't access arduino.cc from here to provide links to the specific boards, and I don't have them on this computer. – CrossRoads Feb 1 '19 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.