Pin mapping a ATmega2561

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

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:

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

Could someone explain this to me?
Thanks.

'2561 only has 54 IO pins, 8 of which are the analog inputs on PORTA, See sheet 5 of the datasheet.

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 :slight_smile:

EDIT: Actually, only "#define digitalPinToInterrupt(p) ... " line is missing, is it the same as in 2560 version?

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....

// 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 ) ) ) ) ) )
	*/

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 GitHub - MCUdude/MegaCore: Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128

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 ?

Pin 14 and 15 on the Arduino Mega 2560 has PCINT's, so it should work

I tried, but it did not work....
Do I have to change anything else ?
Here is the code piece I've changed...

// 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 ) ) ) ) ) )
	*/

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.

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 forum.

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

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:

#define analogInputToDigitalPin(p)  ((p < 8) ? 46 + (7 - (p)) : -1)
//This seem to follow the table pin numbers correctly

Test record

D pin IC pin datasheet pin name pins_arduino.h comment
24
51 PA0 (AD0) PC0
25
50 PA1 (AD1) PC1
26
49 PA2 (AD2) PC2
27
48 PA3 (AD3) PC3
28
47 PA4 (AD4) PC4
29
46 PA5 (AD5) PC5
30
45 PA6 (AD6) PC6
31
44 PA7 (AD7) PC7
32
35 PC0 (A8) PA7
33
36 PC1 (A9) PA6
34
37 PC2 (A10) PA5
35
38 PC3 (A11) PA4
36
39 PC4 (A12) PA3
37
40 PC5 (A13) PA2
38
41 PC6 (A14) PA1
39
42 PC7 (A15) PA0
A0 61 PF0 (ADC0) A0
A1 60 PF1 (ADC1) A1
A2 59 PF2 (ADC2) A2
A3 58 PF3 (ADC3) A3
A4 X PF4 (ADC4/TCK) A4 5V on pin. digitalWrite LOW no affect
A5 X PF5 (ADC5/TMS) A5 5V on pin. digitalWrite LOW no affect
A6 X PF6 (ADC6/TDO) A6 5V on pin. digitalWrite LOW no affect
A7 X PF7 (ADC7/TDI) A7 5V on pin. digitalWrite LOW no affect
A0-7 ADC input test
A0 61 PF0 (ADC0)
A1 60 PF1 (ADC1)
A2 59 PF2 (ADC2)
A3 58 PF3 (ADC3)
A4 X PF4 (ADC4/TCK) unconnected has 5V on pin, ADC reads 1024
A5 X PF5 (ADC5/TMS) unconnected has 5V on pin, ADC reads 1024
A6 X PF6 (ADC6/TDO) unconnected has 5V on pin, ADC reads 1024
A7 X PF7 (ADC7/TDI) unconnected has 5V on pin, ADC reads 1024

Cheers
Alex

pins_arduino.h (8.27 KB)

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. GitHub - MCUdude/MegaCore: Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128

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

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.