Arduino Forum

Using Arduino => Microcontrollers => Topic started by: stank on Jun 03, 2013, 05:40 am

Title: Pin mapping a ATmega2561
Post by: stank on Jun 03, 2013, 05:40 am
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
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 03, 2013, 05:50 am
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:

Code: [Select]

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

part
    id               = "m2561";
    desc             = "ATMEGA2561";
    signature        = 0x1e 0x98 0x02;
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 03, 2013, 06:46 am
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
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 03, 2013, 07:08 am
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.
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 03, 2013, 08:21 am
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
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 03, 2013, 09:20 pm
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.
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 03, 2013, 11:22 pm
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
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 03, 2013, 11:50 pm
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.
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 05, 2013, 12:37 pm
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

Code: [Select]
 $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
};
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 05, 2013, 07:55 pm
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
Code: [Select]

#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:
Code: [Select]

#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
Code: [Select]

#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?
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 06, 2013, 02:22 am
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

Code: [Select]
/*
  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 ) ) ) ) ) )
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 06, 2013, 04:56 am
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.
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 06, 2013, 05:41 am
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.




Code: [Select]
#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.
Code: [Select]
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
};
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 06, 2013, 06:37 pm
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.
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 07, 2013, 03:47 am
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,
Code: [Select]
##############################################################

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.
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 07, 2013, 05:00 am
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.
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 07, 2013, 05:13 am
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
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 07, 2013, 05:21 am
I think so, only differences are the signature bytes, and fewer ports.
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 07, 2013, 11:17 pm
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.

Code: [Select]
// 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
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on Jun 08, 2013, 12:15 am
Cool!

Can you make one up that does the same for a fully broken out 2560?
Title: Re: Pin mapping a ATmega2561
Post by: stank on Jun 08, 2013, 12:57 am
I guess I could but I haven't been able to test this one on hardware. It takes some effort of course and I am a slow programmer/coder. I am trying to learn/get up to speed on these things. I want to also spend some time with the Android developers site. It's all new to me this android stuff.

StanK
Title: Re: Pin mapping a ATmega2561
Post by: przepro on May 21, 2014, 02:33 pm
Hi,
I am a novice user on the AVR and I do not understand something.
Atmega2561 has analog pins 54 .. 61.  So why 46 in:

Code: [Select]
# define analogInputToDigitalPin (p) ((p <8) (p) + 46: -1)?

Could someone explain this to me?
Thanks.
Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on May 21, 2014, 08:38 pm
'2561 only has 54 IO pins, 8 of which are the analog inputs on PORTA, See sheet 5 of the datasheet.
Title: Re: Pin mapping a ATmega2561
Post by: yurislav on Jun 29, 2014, 02:51 pm
Hi,

is complete pins_arduino.h file for atmega2561 uploaded anywhere ?

Examples posted in this thread doest not contains  few arrays, and I feel like I'm getting a bit lost here :)

EDIT: Actually, only "#define digitalPinToInterrupt(p) ... " line is missing, is it the same as in 2560 version?
Title: Re: Pin mapping a ATmega2561
Post by: Cemoka on May 15, 2017, 02:14 am
Hi,

is it possible to include pin14 and 15 to pin change interupt by adding them to code like this:
I'm trying to use pin 15 (rx3)  for Softserial Rx on Mega....


Code: [Select]

// 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) >= 10) && ((p) <= 15)) || \
                                  (((p) >= 50) && ((p) <= 53)) || \
                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )

#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 15)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
                                0 ) )

#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 15)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )

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

Title: Re: Pin mapping a ATmega2561
Post by: hansibull on May 15, 2017, 04:22 pm
Quote
Hi,

is it possible to include pin14 and 15 to pin change interupt by adding them to code like this:
I'm trying to use pin 15 (rx3)  for Softserial Rx on Mega....
Why on earth would you use software serial on a pin that supports HW serial?



Just for reference, If anyone wants a complete package with the ATmega1281 and ATmega2561 all "pin mapped" and ready to go for Arduino IDE, you'll find everything you need on Github https://github.com/MCUdude/MegaCore/ (https://github.com/MCUdude/MegaCore/)
Title: Re: Pin mapping a ATmega2561
Post by: Cemoka on May 15, 2017, 04:37 pm
A GSM Shield for uno and Mega was designed that way.... 

I want to use it with Mega and the official GSM library...

And the question still exists... Can I map it  or not ?
Title: Re: Pin mapping a ATmega2561
Post by: hansibull on May 15, 2017, 06:18 pm
Pin 14 and 15 on the Arduino Mega 2560 has PCINT's, so it should work
Title: Re: Pin mapping a ATmega2561
Post by: Cemoka on May 15, 2017, 09:57 pm
I tried, but it did not work....
Do I have to change anything else ?
Here is the code piece I've changed...

Code: [Select]



// 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) >= 10) && ((p) <= 15)) || \
                                  (((p) >= 50) && ((p) <= 53)) || \
                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )

#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 15)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
                                0 ) )

#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 15)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )

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


Title: Re: Pin mapping a ATmega2561
Post by: CrossRoads on May 15, 2017, 10:08 pm
That code is part of pins_arduino.h, you shouldn't be messing in there.
The 2561 has two serial ports, Serial and Serial1, can't you change your code to use one of those?
Otherwise, use AltSoftwareSerial or NeoSoftwareSerial on the pins for PORTB which have PCINT on them. (AltSoftSerial or NeoSoftSerial ? names are something like those)

Or maybe PORTD bits 0,1,2,3 for INTs 0,1,2,3, or PORTE bits 4,5,6,7 for INTs 4,5,6,7.

If you're using a Mega, then Serial, Serial1, Serial2, and Serial3 are all available. Software serial should be a last resort.
Title: Re: Pin mapping a ATmega2561
Post by: hansibull on May 15, 2017, 10:12 pm
Quote
I tried, but it did not work....
Do I have to change anything else ?
Here is the code piece I've changed...
If this isn't about the ATmega2561, I suggest you start a new thread over at the programming questions (http://forum.arduino.cc/index.php?board=4.0) forum.
Title: Re: Pin mapping a ATmega2561
Post by: alyeomans on Jun 02, 2017, 07:56 am
Hi All

I have been working with what StanK posted (and Crossroads here and on an older thread) with good results on my 2561 custom board. I have tested:
Uart0
Uart1
Digital pins
ADC

I have had some trouble with the digital pins of port A appearing on port C and vice versa. Also A4 to A7 i.e port F, have a constant high voltage (5V) - this also appears on the ADC value and is like the internal pull up is enabled. The first 4 pins of port F i.e A0, A1, A2 and A3 work OK for ADC and digital.

Following is the setup I used:

board.txt
Code: [Select]
mega2561.name=Arduino Mega 2561
mega2561.upload.protocol=wiring
mega2561.upload.maximum_size=258048
mega2561.upload.maximum_data_size=8192
mega2561.upload.tool=avrdude
mega2561.upload.speed=115200

mega2561.bootloader.tool=avrdude
mega2561.bootloader.low_fuses=0x7F
mega2561.bootloader.high_fuses=0x99
mega2561.bootloader.extended_fuses=0xFF
mega2561.bootloader.path=stk500v2
mega2561.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex
mega2561.bootloader.unlock_bits=0x3F
mega2561.bootloader.lock_bits=0x0F

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


The pins_arduino.h attached. Note I have changed the ADC inputs as follows:
Code: [Select]
#define analogInputToDigitalPin(p)  ((p < 8) ? 46 + (7 - (p)) : -1)
//This seem to follow the table pin numbers correctly


Test record
D pinIC pindatasheet pin namepins_arduino.hcomment
24
51PA0 (AD0)PC0
25
50PA1 (AD1)PC1
26
49PA2 (AD2)PC2
27
48PA3 (AD3)PC3
28
47PA4 (AD4)PC4
29
46PA5 (AD5)PC5
30
45PA6 (AD6)PC6
31
44PA7 (AD7)PC7
32
35PC0 (A8)PA7
33
36PC1 (A9)PA6
34
37PC2 (A10)PA5
35
38PC3 (A11)PA4
36
39PC4 (A12)PA3
37
40PC5 (A13)PA2
38
41PC6 (A14)PA1
39
42PC7 (A15)PA0
A061PF0 (ADC0)A0
A160PF1 (ADC1)A1
A259PF2 (ADC2)A2
A358PF3 (ADC3)A3
A4XPF4 (ADC4/TCK)A45V on pin. digitalWrite LOW no affect
A5XPF5 (ADC5/TMS)A55V on pin. digitalWrite LOW no affect
A6XPF6 (ADC6/TDO)A65V on pin. digitalWrite LOW no affect
A7XPF7 (ADC7/TDI)A75V on pin. digitalWrite LOW no affect
A0-7 ADC input test
A061PF0 (ADC0)
A160PF1 (ADC1)
A259PF2 (ADC2)
A358PF3 (ADC3)
A4XPF4 (ADC4/TCK)unconnected has 5V on pin, ADC reads 1024
A5XPF5 (ADC5/TMS)unconnected has 5V on pin, ADC reads 1024
A6XPF6 (ADC6/TDO)unconnected has 5V on pin, ADC reads 1024
A7XPF7 (ADC7/TDI)unconnected has 5V on pin, ADC reads 1024


Cheers
Alex
Title: Re: Pin mapping a ATmega2561
Post by: hansibull on Jun 03, 2017, 01:22 pm
If you don't want to reinvent the wheel, listen up: we already have proper ATmega2561 support for Arduino IDE now. Feel free to do whatever you like, but it's already done. https://github.com/MCUdude/MegaCore (https://github.com/MCUdude/MegaCore)


(http://i.imgur.com/ez5MyvI.jpg)
Title: Re: Pin mapping a ATmega2561
Post by: alyeomans on Jun 06, 2017, 01:59 am
Thanks Hansibul. Works great.

Had some trouble with serial data not clocking properly so checked the clock fuses in boards.txt and updated the fuses and works great.

For all external clock sources I updated to:
low_fuses=0xff
high_fuses=0x99

while on the fuse calculator page I checked the internal clock sources and updated internal fuses to:
low_fuses=0xe2
high_fuses=0xd6

Note I have only checked the 16Mhz.

Have run software serial and attachedInterupt for pin change interrupt at the same time. With above fuse change the board uploads bootloader and can use the serial port programming also (with capacitor between DTR and reset).

Cheers
Al
Title: Re: Pin mapping a ATmega2561
Post by: hansibull on Jun 06, 2017, 03:01 pm
You don't want those fuse settings for the external clock.

For the low fuse setting, you want tu use the full swing oscillator option. It drives the external oscillator with a little more power, resulting in a more stable and noise immune clock. Use 0xF7 for the low fuse.

For the high fuse; you probably don't need JTAG enabled. Boot flash section size does not need to be more than 512 words to fit Optiboot in there, and you _do_ want to enable the boot reset vector. Do you want the EEPROM to be erased every time you upload something new? Probably not. Use 0xD6 for the high fuse.