Pin mapping a ATmega2561

Hello,

I am interested in using a ATmega2561 in place of the Atmega2560 on a custom PCB. I have looked around in the files and can't figure out what needs to be done. I know the internal functions are the same on each part but the 2561 has four less ports. Can any one direct me to the correct way to do this.

Thanks

StanK

You need to create a new section in boards.txt for a '2561 board, with the details of the chip. Also, make some edits to pins_arduino.h to add the '2561 as a recognized processor type, or make a new variant.

Atmega2561 is already in avrdude.conf, so no changes needed there:

#------------------------------------------------------------
# ATmega2561
#------------------------------------------------------------

part
    id               = "m2561";
    desc             = "ATMEGA2561";
    signature        = 0x1e 0x98 0x02;

Thanks for the reply, I have looked over the files you mentioned. I presume that the AVRDUDE assigns the actual pins numbers to the pin names, is that correct? If so, I should only have to delete the ports and associated pin names that are not on the 2561. I don't know where the information you sent me regarding the part ID and such, go?

StanK

The pin mappings are called out in pins-arduino.h The stuff from avrdude.conf just needed to exist. The boards.txt entry needs to reflect the same name that avrdude.conf calls.

If you go here https://github.com/maniacbug/mighty-1284p you can see the kind of things that were setup for the 1284P chip. The 2561 is in between the 1284 and the 2560, so you'll need a pins_arduino.h that will be in between the 2 as well.

Bob,

I have no idea what the labels NOT_A_PORT or NOT_A_TIMER mean or how they are used.

I cant figure out what order of the const to PROMEM means, such as,
const uint8_t PROGMEM digital_pin_to_port_PGM = {
// PORTLIST
// -------------------------------------------
PE , // PE 0 ** 0 ** USART0_RX
PE , // PE 1 ** 1 ** USART0_TX
PE , // PE 4 ** 2 ** PWM2
PE , // PE 5 ** 3 ** PWM3

Nor do I know what to program the fuses to in the boards.txt file, i.e.
mega.bootloader.high_fuses=0xDA
mega.bootloader.extended_fuses=0xF5

I really don’t know what I am doing here.

StanK

There are 3 large arrays, of which you've copied part of the first.

The first list the ports that are assigned from D0 down to whatever the highest D# will be. The 2nd assigns the bits for a specific port

So if the first started PE, PE, PE, PE, PD, PD, PD, PD,

and the second started 0, 1, 2, 3, 7, 6, 5, 4, then DO would map to PORTE-Bit0 D1 >> PE1 D2>> PE2 D3>> PE3 D4>>PD7 D5>>PD6 D6>>PD5 D7>>PD4

And in the 3rd array: the pins that not have OCxA or OCxB would have NOT_A_TIMER, while pins that Did have OCxA or OCxB would be TIMER (or whatever it is) to indicate they are PWM capable output pins.

There are other lines that assign PCINT #s to the pins, and that assign the Analog numbers to the ADC pins. I have a hard time interpreting those as written, would have been easier if those were arrays as well. Get the 3 arrays set up, post what you have, see if one of the software guys will jump into the conversation.

OK,
I’ll try to put these files together. It may be a little while but when I do I’ll post it.

Till then

StanK

Might be easier to study the 2560 section of the distributed pins_arduino.h, make a copy and strip out the unsupported ports, and clean up some. Then copy the boards.txt section of 2560, rename the lines for a new 2561, and, callout the correct chip.

Hello,

I am back with my pins_arduino.h for the ATmega2561. If you care to take a look at it, maybe you can find any errors. I don’t know if I correctly modified the second set of definitions where I have maked them old/new. I am not sure how to write these definitions.
I arranged the pins in an order that reflects the pin order of the chip pins.
What do you think? Oh, I left off the last table because the file was to big

Stank

  $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

#define NUM_DIGITAL_PINS            54
#define NUM_ANALOG_INPUTS           8

#define analogInputToDigitalPin(p)  ((p < 8) ? (p) + 46 : -1)
//old#define analogInputToDigitalPin(p)  ((p < 16) ? (p) + 54 : -1)
#define digitalPinHasPWM(p)         (((p) >= 3 && (p) <= 5) || ((p) >= 12 && (p)<= 15))
//old#define digitalPinHasPWM(p)         (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46))


static const uint8_t SS   = 8;
static const uint8_t SCK  = 9;
static const uint8_t MOSI = 10;
static const uint8_t MISO = 11;

static const uint8_t SCL = 16;
static const uint8_t SDA = 17;

static const uint8_t LED_BUILTIN = 13;

static const uint8_t A0 = 53;
static const uint8_t A1 = 52;
static const uint8_t A2 = 51;
static const uint8_t A3 = 50;
static const uint8_t A4 = 49;
static const uint8_t A5 = 48;
static const uint8_t A6 = 47;
static const uint8_t A7 = 46;

// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
// Pins: 10, 11, 12, 13,  50, 51, 52, 53,  62, 63, 64, 65, 66, 67, 68, 69

//old#define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 13)) || \
//old                                  (((p) >= 50) && ((p) <= 53)) || \
//old                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
#define digitalPinToPCICR(p)    ( (((p) >= 12) && ((p) <= 15)) || \
                                  (((p) >= 8) && ((p) <= 11)) || \
                                  (((p) >= 54) && ((p) <= 53)) ? (&PCICR) : ((uint8_t *)0) )

//old#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
//old                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
//old                                0 ) )
#define digitalPinToPCICRbit(p) ( (((p) >= 12) && ((p) <= 15)) || (((p) >= 8) && ((p) <= 11)) ? 0 : \
                                ( (((p) >= 54) && ((p) <= 53)) ? 2 : \
                                0 ) )


//old#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
//old                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
//old                                ((uint8_t *)0) ) )
#define digitalPinToPCMSK(p)    ( (((p) >= 12) && ((p) <= 15)) || (((p) >= 8) && ((p) <= 11)) ? (&PCMSK0) : \
                                ( (((p) >= 54) && ((p) <= 53)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )

//old#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
//                                ( ((p) == 50) ? 3 : \
//                                ( ((p) == 51) ? 2 : \
//                                ( ((p) == 52) ? 1 : \
//                                ( ((p) == 53) ? 0 : \
//                                ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
//                                0 ) ) ) ) ) )

#define digitalPinToPCMSKbit(p) ( (((p) >= 12) && ((p) <= 15)) ? ((p) - 6) : \
                                ( ((p) == 11) ? 3 : \
                                ( ((p) == 10) ? 2 : \
                                ( ((p) == 9) ? 1 : \
                                ( ((p) == 8) ? 0 : \
                                ( (((p) >= 54) && ((p) <= 53)) ? ((p) - 54) : \
                                0 ) ) ) ) ) )

#ifdef ARDUINO_MAIN

const uint16_t PROGMEM port_to_mode_PGM[] = {
	NOT_A_PORT,
	(uint16_t) &DDRA,
	(uint16_t) &DDRB,
	(uint16_t) &DDRC,
 	(uint16_t) &DDRD,
	(uint16_t) &DDRE,
	(uint16_t) &DDRF,
	(uint16_t) &DDRG,
};

const uint16_t PROGMEM port_to_output_PGM[] = {
	NOT_A_PORT,
	(uint16_t) &PORTA,
(uint16_t) &PORTB,
	(uint16_t) &PORTC,
 	(uint16_t) &PORTD,
	(uint16_t) &PORTE,
	(uint16_t) &PORTF,
	(uint16_t) &PORTG,	
};

const uint16_t PROGMEM port_to_input_PGM[] = {
	NOT_A_PIN,
	(uint16_t) &PINA,
	(uint16_t) &PINB,
	(uint16_t) &PINC,
	(uint16_t) &PIND,
	(uint16_t) &PINE,
	(uint16_t) &PINF,
	(uint16_t) &PING,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
	// PORTLIST		
	// -------------------------------------------		
	PE	, // PE 0 ** 0 ** USART0_RX	
	PE	, // PE 1 ** 1 ** USART0_TX	
	PE	, // PE 2 ** 2 ** D2	
	PE	, // PE 3 ** 3 ** PWM1	
	PE	, // PE 4 ** 4 ** PWM2	
	PE	, // PE 5 ** 5 ** PWM3	
	PE	, // PE 6 ** 6 ** D6	
	PE	, // PE 7 ** 7 ** D7
	PB	, // PB 0 ** 8 ** SPI_SS
	PB	, // PB 1 ** 9 ** SPI_SCK
	PB	, // PB 2 ** 10 ** SPI_MOSI	
	PB	, // PB 3 ** 11 ** SPI_MISO			
	PB	, // PB 4 ** 12 ** PWM4	
	PB	, // PB 5 ** 13 ** PWM5	
	PB	, // PB 6 ** 14 ** PWM6	
	PB	, // PB 7 ** 15 ** PWM7
	PD	, // PD 0 ** 16 ** I2C_SCL
	PD	, // PD 1 ** 17 ** I2C_SDA
	PD	, // PD 2 ** 18 ** USART1_RX		
	PD	, // PD 3 ** 19 ** USART1_TX	
	PD	, // PD 4 ** 20 ** D20
	PD	, // PD 5 ** 21 ** D21		
	PD	, // PD 6 ** 22 ** D22	
	PD	, // PD 7 ** 23 ** D23		
	PC	, // PC 0 ** 24 ** D24	
	PC	, // PC 1 ** 25 ** D25	
	PC	, // PC 2 ** 26 ** D26	
	PC	, // PC 3 ** 27 ** D27	
	PC	, // PC 4 ** 28 ** D28	
	PC	, // PC 5 ** 29 ** D29	
	PC	, // PC 6 ** 30 ** D30	
	PC	, // PC 7 ** 31 ** D31		
	PA	, // PA 7 ** 32 ** D32	
	PA	, // PA 6 ** 33 ** D33	
	PA	, // PA 5 ** 34 ** D34	
	PA	, // PA 4 ** 35 ** D35	
	PA	, // PA 3 ** 36 ** D36	
	PA	, // PA 2 ** 37 ** D37	
	PA	, // PA 1 ** 38 ** D38	
	PA	, // PA 0 ** 39 ** D39
	PG	, // PG 0 ** 40 ** D40	
	PG	, // PG 1 ** 41 ** D41	
	PG	, // PG 2 ** 42 ** D42
	PG	, // PG 3 ** 43 ** D43	
	PG	, // PG 4 ** 44 ** D44	
	PG	, // PG 5 ** 45 ** PWM8		
	PF	, // PF 7 ** 46 ** A7	
	PF	, // PF 6 ** 47 ** A6	
	PF	, // PF 5 ** 48 ** A5	
	PF	, // PF 4 ** 49 ** A4	
	PF	, // PF 3 ** 50 ** A3	
	PF	, // PF 2 ** 51 ** A2	
	PF	, // PF 1 ** 52 ** A1	
	PF	, // PF 0 ** 53 ** A0
	
	
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
	// PIN IN PORT		
	// -------------------------------------------		
	_BV( 0 )	, // PE 0 ** 0 ** USART0_RX	
	_BV( 1 )	, // PE 1 ** 1 ** USART0_TX	
	_BV( 2 )	, // PE 2 ** 2 ** D2	
	_BV( 3 )	, // PE 3 ** 3 ** PWM1	
	_BV( 4 )	, // PE 4 ** 4 ** PWM2
	_BV( 5 )	, // PE 5 ** 5 ** PWM3	
	_BV( 6 )	, // PE 6 ** 6 ** D6
	_BV( 7 )	, // PE 7 ** 7 ** D7
	_BV( 0 )	, // PB 0 ** 8 ** SPI_SS
	_BV( 1 )	, // PB 1 ** 9 ** SPI_SCK	
	_BV( 2 )	, // PB 2 ** 10 ** SPI_MOSI	
	_BV( 3 )	, // PB 3 ** 11 ** SPI_MISO		
	_BV( 4 )	, // PB 4 ** 12 ** PWM4	
	_BV( 5 )	, // PB 5 ** 13 ** PWM5	
	_BV( 6 )	, // PB 6 ** 14 ** PWM6	
	_BV( 7 )	, // PB 7 ** 15 ** PWM7
	_BV( 0 )	, // PD 0 ** 16 ** I2C_SCL	
	_BV( 1 )	, // PD 1 ** 17 ** I2C_SDA
	_BV( 2 )	, // PD 2 ** 18 ** USART1_RX		
	_BV( 3 )	, // PD 3 ** 19 ** USART1_TX	
	_BV( 4 )	, // PD 4 ** 20 ** D20
	_BV( 5 )	, // PD 5 ** 21 ** D21
	_BV( 6 )	, // PD 6 ** 22 ** D22
	_BV( 7 )	, // PD 7 ** 23 ** D23
	_BV( 0 )	, // PC 0 ** 24 ** D24	
	_BV( 1 )	, // PC 1 ** 25 ** D25	
	_BV( 2 )	, // PC 2 ** 26 ** D26	
	_BV( 3 )	, // PC 3 ** 27 ** D27	
	_BV( 4 )	, // PC 4 ** 28 ** D28	
	_BV( 5 )	, // PC 5 ** 29 ** D29	
	_BV( 6 )	, // PC 6 ** 30 ** D30	
	_BV( 7 )	, // PC 7 ** 31 ** D31
 	_BV( 7 )	, // PA 7 ** 32 ** D32	
	_BV( 6 )	, // PA 6 ** 33 ** D33	
	_BV( 5 )	, // PA 5 ** 34 ** D34	
	_BV( 4 )	, // PA 4 ** 35 ** D35	
	_BV( 3 )	, // PA 3 ** 36 ** D36	
	_BV( 2 )	, // PA 2 ** 37 ** D37	
	_BV( 1 )	, // PA 1 ** 38 ** D38	
	_BV( 0 )	, // PA 0 ** 39 ** D39	
	_BV( 0 )	, // PG 0 ** 40 ** D40	
	_BV( 1 )	, // PG 1 ** 41 ** D41	
	_BV( 2 )	, // PG 2 ** 42 ** D42	
	_BV( 3 )	, // PG 3 ** 43 ** D43
	_BV( 4 )	, // PG 4 ** 44 ** D44
	_BV( 5 )	, // PG 5 ** 45 ** PWM8
	_BV( 7 )	, // PF 7 ** 46 ** A7	
	_BV( 6 )	, // PF 6 ** 47 ** A6	
	_BV( 5 )	, // PF 5 ** 48 ** A5	
	_BV( 4 )	, // PF 4 ** 49 ** A4	
	_BV( 3 )	, // PF 3 ** 50 ** A3	
	_BV( 2 )	, // PF 2 ** 51 ** A2	
	_BV( 1 )	, // PF 1 ** 52 ** A1	
	_BV( 0 )	, // PF 0 ** 53 ** A0	
};

Looks pretty good so far.

Third array will be mostly NOT_A_TIMER except for the 8 PWM pins, 3-4-5, 12-15, 45

This line

#define digitalPinHasPWM(p)         (((p) >= 3 && (p) <= 5) || ((p) >= 12 && (p)<= 15))

need 45 in it for the 8th PWM
(Seems redundant with 3rd array, doesn’t it? Am sure there is some reason behind it tho)

This looks a little off:

#define digitalPinToPCICR(p)    ( (((p) >= 12) && ((p) <= 15)) || \
                                  (((p) >= 8) && ((p) <= 11)) || \
                                  (((p) >= 54) && ((p) <= 53)) ? (&PCICR) : ((uint8_t *)0) )

as the PCINTs are only from 8 to 15.
Same for the other PCINT related sections.
I didn’t check the data sheet to see if PCMSK0 is the right one for PortB
Same for PCICR.
Also

#define digitalPinToPCICRbit(p) ( (((p) >= 12) && ((p) <= 15)) || (((p) >= 8) && ((p) <= 11)) ? 0 : \
                                ( (((p) >= 54) && ((p) <= 53)) ? 2 : \
                                0 ) )

I don’t know what the "? 0: \ " means on the end of the line, need some one a little smarter to explain that.

I see there are 8 hardware interrupt pins in place of PCINTs.

This note:
(I’ve deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)

Was RX0, TX0, RX1, TX1 or something similar defined earlier?

I included the first part of the file with this code and I left off the tables because I think they are correct and they won’t fit here. I changed the digitalPinHasPWM definitions to include DP45 and the reason I have (((p) >= 54) && ((p) <= 53)) in the others, digitalPinToPCMSKxxx, is that I don’t know what effect it would have if I removed the statement. The way I wrote it, the return value would be false under all conditions and wouldn’t make any assignments for that part. I hope this will work. What do you think?

StanK

/*
  pins_arduino.h - Pin definition functions for Arduino
  Part of Arduino - http://www.arduino.cc/

  Copyright (c) 2007 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA

  $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

#define NUM_DIGITAL_PINS            54
#define NUM_ANALOG_INPUTS           8

#define analogInputToDigitalPin(p)  ((p < 8) ? (p) + 46 : -1)
//old#define analogInputToDigitalPin(p)  ((p < 16) ? (p) + 54 : -1)
#define digitalPinHasPWM(p)         ( ((p) >= 3 && (p) <= 5) || ((p) >= 12 && (p)<= 15) || ((p) == 45 ) )
//old#define digitalPinHasPWM(p)         (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46))


static const uint8_t SS   = 8;
static const uint8_t SCK  = 9;
static const uint8_t MOSI = 10;
static const uint8_t MISO = 11;

static const uint8_t SCL = 16;
static const uint8_t SDA = 17;

static const uint8_t LED_BUILTIN = 13;

static const uint8_t A0 = 53;
static const uint8_t A1 = 52;
static const uint8_t A2 = 51;
static const uint8_t A3 = 50;
static const uint8_t A4 = 49;
static const uint8_t A5 = 48;
static const uint8_t A6 = 47;
static const uint8_t A7 = 46;

// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
// Pins: 10, 11, 12, 13,  50, 51, 52, 53,  62, 63, 64, 65, 66, 67, 68, 69

//old#define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 13)) || \
//old                                  (((p) >= 50) && ((p) <= 53)) || \
//old                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
#define digitalPinToPCICR(p)    ( (((p) >= 12) && ((p) <= 15)) || \
                                  (((p) >= 8) && ((p) <= 11)) ? (&PCICR) : ((uint8_t *)0) )


//old#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
//old                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
//old                                0 ) )
#define digitalPinToPCICRbit(p) ( (((p) >= 12) && ((p) <= 15)) || (((p) >= 8) && ((p) <= 11)) ? 0 : \
                                ( (((p) >= 54) && ((p) <= 53)) ? 2 : \
                                0 ) )


//old#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
//old                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
//old                                ((uint8_t *)0) ) )
#define digitalPinToPCMSK(p)    ( (((p) >= 12) && ((p) <= 15)) || (((p) >= 8) && ((p) <= 11)) ? (&PCMSK0) : \
                                ( (((p) >= 54) && ((p) <= 53)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )

//old#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
//                                ( ((p) == 50) ? 3 : \
//                                ( ((p) == 51) ? 2 : \
//                                ( ((p) == 52) ? 1 : \
//                                ( ((p) == 53) ? 0 : \
//                                ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
//                                0 ) ) ) ) ) )

#define digitalPinToPCMSKbit(p) ( (((p) >= 12) && ((p) <= 15)) ? ((p) - 6) : \
                                ( ((p) == 11) ? 3 : \
                                ( ((p) == 10) ? 2 : \
                                ( ((p) == 9) ? 1 : \
                                ( ((p) == 8) ? 0 : \
                                ( (((p) >= 54) && ((p) <= 53)) ? ((p) - 54) : \
                                0 ) ) ) ) ) )

Give it a try and do some testing. I think the 53/54 stuff can likely be deleted from t he PCINT stuff, like you I am not sure what the best way to clean that up is.

Well, I cleaned up some of the definitions. I think I got it right except I don’t know what the -6 is on this statement, It’s on the origonal definition.
#define digitalPinToPCMSKbit(p) ( (((p) >= 12) && ((p) <= 15)) ? ((p) - 6) : \

I still have to do the boards.txt. I am still not sure about these settings,
mega.bootloader.high_fuses=0xDA
mega.bootloader.extended_fuses=0xF5
I suppose I could leave them as they are.

I don’t have any hardware to try it on but I could try to compile it.

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

#define NUM_DIGITAL_PINS            54
#define NUM_ANALOG_INPUTS           8

#define analogInputToDigitalPin(p)  ((p < 8) ? (p) + 46 : -1)

#define digitalPinHasPWM(p)         ( ((p) >= 3 && (p) <= 5) || ((p) >= 12 && (p)<= 15) || ((p) == 45 ) )


static const uint8_t SS   = 8;
static const uint8_t SCK  = 9;
static const uint8_t MOSI = 10;
static const uint8_t MISO = 11;

static const uint8_t SCL = 16;
static const uint8_t SDA = 17;

static const uint8_t LED_BUILTIN = 13;

static const uint8_t A0 = 53;
static const uint8_t A1 = 52;
static const uint8_t A2 = 51;
static const uint8_t A3 = 50;
static const uint8_t A4 = 49;
static const uint8_t A5 = 48;
static const uint8_t A6 = 47;
static const uint8_t A7 = 46;

// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
// Pins: 10, 11, 12, 13,  50, 51, 52, 53,  62, 63, 64, 65, 66, 67, 68, 69

#define digitalPinToPCICR(p)    ( (((p) >= 8) && ((p) <= 15)) || ? (&PCICR) : ((uint8_t *)0) )

#define digitalPinToPCICRbit(p) ( (((p) >= 8) && ((p) <= 15)) ? 0 : 0 )

#define digitalPinToPCMSK(p)    ( (((p) >= 8) && ((p) <= 15)) ? (&PCMSK0) : ((uint8_t *)0) )

#define digitalPinToPCMSKbit(p) ( (((p) >= 12) && ((p) <= 15)) ? ((p) - 6) : \
                                ( ((p) == 11) ? 3 : \
                                ( ((p) == 10) ? 2 : \
                                ( ((p) == 9) ? 1 : \
                                ( ((p) == 8) ? 0 : 0  ) ) ) ) )

#ifdef ARDUINO_MAIN

Also, here is the last table I didn’t include before.

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
	// TIMERS		
	// -------------------------------------------		
	NOT_ON_TIMER	, // PE 0 ** 0 ** USART0_RX	
	NOT_ON_TIMER	, // PE 1 ** 1 ** USART0_TX	
	NOT_ON_TIMER	, // PE 2 ** 2 ** D2	
	TIMER3A	  	 	, // PE 3 ** 3 ** PWM1	
	TIMER3B			, // PE 4 ** 4 ** PWM2
	TIMER3C			, // PE 5 ** 5 ** PWM3
	NOT_ON_TIMER	, // PE 6 ** 6 ** D6
	NOT_ON_TIMER	, // PE 7 ** 7 ** D7
	NOT_ON_TIMER	, // PB 0 ** 8 ** SPI_MISO	
	NOT_ON_TIMER	, // PB 1 ** 9 ** SPI_MOSI	
	NOT_ON_TIMER	, // PB 2 ** 10 ** SPI_SCK	
	NOT_ON_TIMER	, // PB 3 ** 11 ** SPI_SS
	TIMER2A		, // PB 4 ** 12 ** PWM4	
	TIMER1A		, // PB 5 ** 13 ** PWM5	
	TIMER1B		, // PB 6 ** 14 ** PWM6	
	TIMER0A		, // PB 7 ** 15 ** PWM7
	NOT_ON_TIMER	, // PD 0 ** 16 ** I2C_SCL
	NOT_ON_TIMER	, // PD 1 ** 17 ** I2C_SDA	
	NOT_ON_TIMER	, // PD 2 ** 18 ** USART1_RX	
	NOT_ON_TIMER	, // PD 3 ** 19 ** USART1_TX
	NOT_ON_TIMER	, // PD 4 ** 20 ** D20
	NOT_ON_TIMER	, // PD 5 ** 21 ** D21
	NOT_ON_TIMER	, // PD 6 ** 22 ** D22
	NOT_ON_TIMER	, // PD 7 ** 23 ** D23		
	NOT_ON_TIMER	, // PC 0 ** 24 ** D24	
	NOT_ON_TIMER	, // PC 1 ** 25 ** D25	
	NOT_ON_TIMER	, // PC 2 ** 26 ** D26	
	NOT_ON_TIMER	, // PC 3 ** 27 ** D27	
	NOT_ON_TIMER	, // PC 4 ** 28 ** D28	
	NOT_ON_TIMER	, // PC 5 ** 29 ** D29	
	NOT_ON_TIMER	, // PC 6 ** 30 ** D30	
	NOT_ON_TIMER	, // PC 7 ** 31 ** D31		
	NOT_ON_TIMER	, // PA 7 ** 32 ** D32	
	NOT_ON_TIMER	, // PA 6 ** 33 ** D33	
	NOT_ON_TIMER	, // PA 5 ** 34 ** D34	
	NOT_ON_TIMER	, // PA 4 ** 35 ** D35	
	NOT_ON_TIMER	, // PA 3 ** 36 ** D36	
	NOT_ON_TIMER	, // PA 2 ** 37 ** D37	
	NOT_ON_TIMER	, // PA 1 ** 38 ** D38	
	NOT_ON_TIMER	, // PA 0 ** 39 ** D39	
	NOT_ON_TIMER	, // PG 0 ** 40 ** D40	
	NOT_ON_TIMER	, // PG 1 ** 41 ** D41		
	NOT_ON_TIMER	, // PG 2 ** 42 ** D42	
	NOT_ON_TIMER	, // PG 3 ** 43 ** D43	
	NOT_ON_TIMER	, // PG 4 ** 44 ** D44	
	TIMER0B		, // PG 5 ** 45 ** PWM4		
	NOT_ON_TIMER	, // PF 7 ** 46 ** A7	
	NOT_ON_TIMER	, // PF 6 ** 47 ** A6	
	NOT_ON_TIMER	, // PF 5 ** 48 ** A5	
	NOT_ON_TIMER	, // PF 4 ** 49 ** A4	
	NOT_ON_TIMER	, // PF 3 ** 50 ** A3	
	NOT_ON_TIMER	, // PF 2 ** 51 ** A2	
	NOT_ON_TIMER	, // PF 1 ** 52 ** A1	
	NOT_ON_TIMER	, // PF 0 ** 53 ** A0	
};

I bet you that should be adjusted to be -8 so that 12-13-14-15 end up as 4-5-6-7 to continue from the 0-1-2-3 below it. Or even simpler: ( ((p) == 15) ? 7 : \ ( ((p) == 14) ? 6 : \ ( ((p) == 13) ? 5 : \ ( ((p) == 12) ? 4 : \

Uncommented cryptic C/C++ programming, hard to follow most of the time.

Last array looks good.

Yeah,, I figured that the -6 should be a -8 after I sent it. Well now I seem to have other problems. I ran the compiler with the new boards.txt which looks this,

##############################################################

mega2560.name=Arduino Mega 2560 or Mega ADK

mega2560.upload.protocol=wiring
mega2560.upload.maximum_size=258048
mega2560.upload.speed=115200

mega2560.bootloader.low_fuses=0xFF
mega2560.bootloader.high_fuses=0xD8
mega2560.bootloader.extended_fuses=0xFD
mega2560.bootloader.path=stk500v2
mega2560.bootloader.file=stk500boot_v2_mega2560.hex
mega2560.bootloader.unlock_bits=0x3F
mega2560.bootloader.lock_bits=0x0F

mega2560.build.mcu=atmega2560
mega2560.build.f_cpu=16000000L
mega2560.build.core=arduino
mega2560.build.variant=mega

##############################################################

mega2561.name=Arduino Mega 2561

mega2561.upload.protocol=wiring
mega2561.upload.maximum_size=258048
mega2561.upload.speed=115200

mega2561.bootloader.low_fuses=0xFF
mega2561.bootloader.high_fuses=0xD8
mega2561.bootloader.extended_fuses=0xFD
mega2561.bootloader.path=stk500v2
mega2561.bootloader.file=stk500boot_v2_mega2561.hex
mega2561.bootloader.unlock_bits=0x3F
mega2561.bootloader.lock_bits=0x0F

mega2561.build.mcu=atmega2561
mega2561.build.f_cpu=16000000L
mega2561.build.core=arduino
mega2561.build.variant=mega2561

##############################################################

It's the second list. I don't know it it is correct but the compiler compiles with it.

The problem I have now is with the softwareSerial. I can compile the example with any board except the Mega2560. I am not using the Mega2561 data yet.

I think I will post my problem with a new topic.

Looks good to me. I look forward to creating a board to use that.

Software serial, need to use pins that have PCINT apparently.
Have found it takes up too much processing power on other projects, added an I2C/SPI dual uart instead to have 6 serial lines.

SC16IS752_SC16IS762_SPI_dual_UART.pdf (292 KB)

Well I hoped this exercise help out with the pin outs for who ever may need them. I also add the 8PWM at DP45. I don’t need to use SoftwareSerial with this project as far as I can tell but for some reason it seems to think it should be there, sometimes. I have a post on the Programming topic heading.

Oh one other thing, do Know if the fuses on the board.txt file are the same as the Mega2560?

StanK

I think so, only differences are the signature bytes, and fewer ports.

I discovered an error in one line if my tables. I left in an OR expression ||, see where it says HERE! Remove the ||. Now it compiles OK.

// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
// Pins: 10, 11, 12, 13,  50, 51, 52, 53,  62, 63, 64, 65, 66, 67, 68, 69

#define digitalPinToPCICR(p)    ( (((p) >= 8) && ((p) <= 15)) HERE! ? (&PCICR) : ((uint8_t *)0) )

#define digitalPinToPCICRbit(p) ( (((p) >= 8) && ((p) <= 15)) ? 0 : 0 )

#define digitalPinToPCMSK(p)    ( (((p) >= 8) && ((p) <= 15)) ? (&PCMSK0) : ((uint8_t *)0) ) 

#define digitalPinToPCMSKbit(p) ( (((p) >= 12) && ((p) <= 15)) ? ((p) - 8) : \
                                ( ((p) == 11) ? 3 : \
                                ( ((p) == 10) ? 2 : \
                                ( ((p) == 9) ? 1 : \
                                ( ((p) == 8) ? 0 : 0  ) ) ) ) )

StanK

Cool!

Can you make one up that does the same for a fully broken out 2560?