Help me understand pins.h

Hi All…

A friend of mine built a prototype board based on a Atmega1284P-PU (the DIP package) and it runs great, with all the software I wrote for it. I built a surface mount version (using a Atmega1284P-AU) with his help, but the pin numbering is different. So, the code does not work.

It seems to me that I need to modify the Arduino pin to port mappings, although I am not sure. I don’t really understand what this mapping is for and how it works. If I did, well I guess I could get this done. Can someone fill me in or let me know where to find this information?

Thanks…

Okay I am making some progress on this. Apparently int he various pins_???????.cxx files there is a mapping, starting with pin 1, of what port is on what pin. Of course the data structures are zero based but that does not matter. I am still trying to figure out, though, how they tell it how many non-port pins are inbetween the contigious line of pins that are in a port.

Code (that does not run properly) thus far:

#define PA 1
#define PB 2
#define PC 3
#define PD 4

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] =
{
    NOT_A_PORT,
    &DDRA,
    &DDRB,
    &DDRC,
    &DDRD,
};

const uint16_t PROGMEM port_to_output_PGM[] =
{
    NOT_A_PORT,
    &PORTA,
    &PORTB,
    &PORTC,
    &PORTD,
};

const uint16_t PROGMEM port_to_input_PGM[] =
{
    NOT_A_PORT,
    &PINA,
    &PINB,
    &PINC,
    &PIND,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] =
{
    PB, /* 0 */
    PB,
    PB,
    PD, /* 3 */
    PD,
    PD,
    PD,
    PD,
    PD, /* 8 */
    PD,
    PD,
    PC, /* 11 */
    PC,
    PC,
    PC,
    PC,
    PC, /* 16 */
    PC,
    PC,
    PA,
    PA,
    PA,
       PA,
    PA,
    PA, /* 24 */
    PA,
    PA,
    PB,
    PB,
    PB,
    PB,
    PB  /* 31 */
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
{
    _BV(5), /* 5, port B */
    _BV(6),
    _BV(7),
    _BV(0), /* 0, port D */
    _BV(1),
    _BV(2),
    _BV(3),
    _BV(4),
    _BV(5), /* 5, port D */
    _BV(6),
    _BV(7),
    _BV(0), /* 0, port C */
    _BV(1),
    _BV(2),
    _BV(3),
    _BV(4),
    _BV(5), /* 5, port C */
    _BV(6),
    _BV(7),
    _BV(7),
    _BV(6),
    _BV(5),
    _BV(4),
    _BV(3),
    _BV(2), /* 24, port A */
    _BV(1),
    _BV(0), /* 0, port B */
    _BV(0),
    _BV(1),
    _BV(2),
    _BV(3),
    _BV(4)
};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
{
    NOT_ON_TIMER,   /* 0  - PB5 */
    NOT_ON_TIMER,   /* 1  - PB6 */
    NOT_ON_TIMER,   /* 2  - PB7 */
    NOT_ON_TIMER,         /* 3  - PD0 */
    NOT_ON_TIMER,       /* 4  - PD1 */
    NOT_ON_TIMER,   /* 5  - PD2 */
    NOT_ON_TIMER,   /* 6  - PD3 */
    TIMER1B,    /* 7  - PD4 */
    TIMER1A,    /* 8  - PD5 */
    TIMER2B,    /* 9  - PD6 */
    TIMER2A,    /* 10 - PD7 */
    NOT_ON_TIMER,   /* 11 - PC0 */
    NOT_ON_TIMER,         /* 12 - PC1 */
    NOT_ON_TIMER,         /* 13 - PC2 */
    NOT_ON_TIMER,         /* 14 - PC3 */
    NOT_ON_TIMER,         /* 15 - PC4 */
    NOT_ON_TIMER,   /* 16 - PC5 */
    NOT_ON_TIMER,   /* 17 - PC6 */
    NOT_ON_TIMER,   /* 18 - PC7 */
    NOT_ON_TIMER,   /* 19 - PA7 */
    NOT_ON_TIMER,   /* 20 - PA6 */
    NOT_ON_TIMER,   /* 21 - PA5 */
    NOT_ON_TIMER,   /* 22 - PA4 */
    NOT_ON_TIMER,   /* 23 - PA3 */
    NOT_ON_TIMER,   /* 24 - PA2 */
    NOT_ON_TIMER,   /* 25 - PA1 */
    NOT_ON_TIMER,   /* 26 - PA0 */
    NOT_ON_TIMER,   /* 27 - PB0 */
    NOT_ON_TIMER,   /* 28 - PB1 */
    NOT_ON_TIMER,   /* 29 - PB2 */
    TIMER0A,   /* 30 - PB3 */
    TIMER0B   /* 31 - PB4 */
};

skyjumper: A friend of mine built a prototype board based on a Atmega1284P-PU (the DIP package) and it runs great,

Sorry this is not going to help you, but I am thinking of doing the same thing, so I am curious about this. What was needed to get a sketch working on the 1284? Did you just set the 'board' to 'Arduino Mega (ATmega1280)' ??

Well you need an appropriate entry in the board.txt file for a 1284P. The baud rate specified in the board.txt file has to match the baud rate coded into the bootloader. You'll also need to put a bootloader on to the 1284P, which you can do a few different ways. But that's mostly it.