Atmega2561

I was asked about Atmega2561, a 2560 variant in 64 TQFP package.
So I decided to see what I could do to make a 2561 system on a chip type design.
Here’s what I came up with.
Anyone have suggestions for Digital IO pin assignments? Is there a 2561 board type already that is Mega-like?
Anyone have any suggestions for the design? I merely broke out all the pins to 0.1" pitch headers, added bare-minimum components (6 x 35mm SMD crystal & caps, pullup Resistor, decoupling & DTR caps) to the bottom, and broke out a Serial interface and ICSP header.
Anything else, add it to your external design. All fits on a 1.6" x 1.4" board.

Or leave the components off the bottom and just use it as a breakout board.

I have designed similar 2560 board which I am having a couple assembled shortly, just waiting on solder paste stencils.

This is probably useless information, but here it is, just in case.
There is a board out there based on the 1281: the Libelium Waspmote.
I think that is the 128K version of the 2561, I will check.
It uses a modified IDE for programming, but it may already feature a pins layout file.
I will check when I get to a machine that has it installed and post here, in case it is useful to you.

Short of that, why not go with Bobuino++... :wink:

2561 is already in avrdude.conf, so maybe I can get away with just this in boards.txt and a new pins_Arduino.h variant:

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_mega2560.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=mega

And this for pins_arduino.h entry for the 2561. Needs a little work in PCINT area still, I don’t follow what it’s doing yet.
I trimmed a bunch of similar stuff that I do understand so it fits here, mostly so the port assignments I am contemplating can be seen.

/*
  pins_arduino.h - Pin definition functions for Arduino
  Part of Arduino - [iurl=http://www.arduino.cc/]http://www.arduino.cc/[/iurl]
  Copyright (c) 2007 David A. Mellis
  This library is free software; you can redistribute it and/or
... bunch of stuff trimmed for posting ...
*/
/* modified for 2561 with fewer ports  RWP 2015 */
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define NUM_DIGITAL_PINS            46
#define NUM_ANALOG_INPUTS           8
#define analogInputToDigitalPin(p)  ((p < 8) ? (p) + 46 : -1)
#define digitalPinHasPWM(p)         (p==3 || p==4 || p==5 || p==12 || p==13 || p==14 || p==15 || p==45)
static const uint8_t SS   = 8;
static const uint8_t MOSI = 10;
static const uint8_t MISO = 11;
static const uint8_t SCK  = 9;
static const uint8_t SDA = 17;
static const uint8_t SCL = 16;
static const uint8_t LED_BUILTIN = 9;
static const uint8_t A0 = 46;
static const uint8_t A1 = 47;
static const uint8_t A2 = 48;
static const uint8_t A3 = 49;
static const uint8_t A4 = 50;
static const uint8_t A5 = 51;
static const uint8_t A6 = 52;
static const uint8_t A7 = 53;

// 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)
// 2560: Pins: 10, 11, 12, 13,  50, 51, 52, 53,  62, 63, 64, 65, 66, 67, 68, 69
// 2561 PCINTs: 8-15, all on PORTB  - I DON"T KNOW WHAT TO DO HERE
#define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 13)) || \
                                  (((p) >= 50) && ((p) <= 53)) || \
                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
                                0 ) )
#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )
#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 ) ) ) ) ) )
#ifdef ARDUINO_MAIN
// bunch of stuff trimmed for posting ...
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 **  
 PE , // PE 3 ** 3 ** PWM0 
 PE , // PE 4 ** 4 ** PWM1 
 PE , // PE 5 ** 5 ** PWM2 
 PE , // PE 6 ** 6 **  
 PE , // PE 7 ** 7 ** 
 
 PB , // PH 0 ** 8 ** SS 
 PB , // PH 1 ** 9 ** SCK
 PB , // PB 2 ** 10 ** MOSI
 PB , // PB 3 ** 11 ** MISO
 PB , // PB 4 ** 12 ** PWM3
 PB , // PB 5 ** 13 ** PWM4
 PB , // PJ 6 ** 14 ** PWM5
 PB , // PJ 7 ** 15 ** PWM6
 
 PD , // PD 0 ** 16 ** I2C - SCL - INT0 
 PD , // PD 1 ** 17 ** I2C - SDA - INT1 
 PD , // PD 2 ** 18 ** USART1_RX - INT2 
 PD , // PD 3 ** 19 ** USART1_TX - INT3 
 PD , // PD 4 ** 20 ** 
 PD , // PD 5 ** 21 **  
 PD , // PD 6 ** 22 ** 
 PD , // PD 7 ** 23 **
 PA , // PA 0 ** 24 ** D24 
 PA , // PA 1 ** 25 ** D25 
 PA , // PA 2 ** 26 ** D26 
 PA , // PA 3 ** 27 ** D27 
 PA , // PA 4 ** 28 ** D28 
 PA , // PA 5 ** 29 ** D29 
 PA , // PC 6 ** 30 ** D30 
 PA , // PC 7 ** 31 ** D31
 
 PC , // PC 0 ** 32 ** D32 
 PC , // PC 1 ** 33 ** D33 
 PC , // PC 2 ** 34 ** D34 
 PC , // PC 3 ** 35 ** D35 
 PC , // PC 4 ** 36 ** D36 
 PC , // PC 5 ** 37 ** D37 
 PC , // PC 6 ** 38 ** D38 
 PC , // PC 7 ** 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 ** D45
 
 PF , // PF 0 ** 46 ** D46 
 PF , // PF 1 ** 47 ** D47 
 PF , // PF 2 ** 48 ** D48 
 PF , // PF 3 ** 49 ** D49 
 PF , // PF 4 ** 50 ** D50 
 PF , // PF 5 ** 51 ** D51 
 PF , // PF 6 ** 52 ** D52 
 PB , // PF 7 ** 53 ** D53 
 
};
// other similar tables trimmed for posting
#endif
#endif

pins_arduino_2561.h (9.85 KB)

For the pin change interrupts, something like this shoudl work for your proposed mapping…?

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

#define digitalPinToPCICRbit(p) (((p) >= 8) && ((p) <= 15)) ? 0 : ???? ) //What to return when it's not a valid pin? 0? In which case this could be shortened to 0. 

#define digitalPinToPCMSK(p)    (((p) >= 8) && ((p) <= 15)) ? (&PCMSK0) : ((uint8_t *)0) )
#define digitalPinToPCMSKbit(p) (((p) >= 8) && ((p) <= 15)) ? p-8 : ??? ) //again, as above...

They take the pin number, and return the PCICR register (on some chips, this register isn’t PCICR - the same functionality is on some general interrupt control register), and the bit within the PCICR register that controls enabling this PCINT. Likewise, the PCMSK ones return the PCMSKn register for a given pin, and the bit within that register for that specific pin out of the 8 it could be.

Thanks, will see if I can pull it all together tonight and try a test compile.
You think the mapping is okay? I was thinking maybe match some of the Mega's, but the pins there are just all over the place where they left out stuff to make the IO fit the 70 pins they used for Serial, I2C, SPI, interrupts, and PWM, whereas I am using all of them here. I kind of like the idea of complete contiguous ports too, altho that is easily addressed in software if one wants to use a whole part (direct port manipulation, or with arrays).

I like your mapping (and I also like being able to put whole ports onto consecutive pin numbers, with the pins right next to eachother) - they made a godawful mess out of the pin mapping on the mega, IMO. But my opinion probably shouldn't count for too much, since I don't use any AVR's that big (I haven't even used those 1284p boards you sold me - I assembled one, but didn't go beyond that - I don't know how people fill hundreds of KB of flash!

You've got at least one typo in that table (last line is PB should probably be PF), and multiple comments that haven't been adjusted, too.

How about some LEDs. :sob:

After this is made, create a mother board that this plugs onto (header pins or machined sockets).
Possible RTC, FTDI card, etc.
Headers for shields.

Diode across R30?
SDA/SCL/GND header?
Any need to add loading option resistor to the crystal?
Mounting holes in the four corners?

Edit: two header pins on reset where you can short to cause a reset

Maybe have 5V and GND header pins to bring power onboard.

Might be wise to have a reversed biased diode +5 to GND to protect against reversed power supply connections.

10uH between VCC an AVCC?

Edit:
It might be nice to have a TXD1 and RXD1 with GND (3 pin) header.

Should have room for one of these smd switches for reset:

2015-10-21_19-07-27.jpg
.

Ok, here’s what I have now.

  • Added Names per pins_arduino.h previously posted with PWM~, I2C, SPI, and Serial ports noted.
  • Added Power LED
  • Added SCK LED (“D13”, but on D9 here)
  • Added I2C header
  • Rearranged Rx1/Tx1/Gnd so they are 3 pins in a row on the header
  • (didn’t do anything different for Rx0/Tx0 since they are on the “FTDI” header)
  • Rearranged SDA/SCL/Gnd so they are 3 pins in a row on the header
  • Added some more +5/Gnd headers
  • Didn’t add a Reset Switch - user can add one off board, or jumper one across ICSP header for debugging
  • Added a Reset Diode
  • Didn’t add 10uH to AVCC. Too messy with Jumper to disconnect FTDI power from rest of board power.
  • Didn’t add reverse polarity protection. Be careful. Also drops too much voltage if want to run from 3V, and somewhat with running from 3.7V, 4.5V (battery).
  • Added 2mm mounting holes.
  • Added pads for Crystal resistor. Have not seen the need for one any of my boards yet so I do not plan to install one.
    (these captures may differ a little as I tweaked things up)

"Motherboard" concept, will have to work on that.

Little tweak here:

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

Little tweak in pins_arduino.h, and it shows up & compiles Blink ok!

C:\Arduino\hardware\tools\avr\bin\avr-gcc -Os -Wl,--gc-sections -mmcu=atmega2561 -o 
C:\Users\CROSSR~1.CRO\AppData\Local\Temp\build9182687107596139226.tmp\Blink.cpp.elf 
C:\Users\CROSSR~1.CRO\AppData\Local\Temp\build9182687107596139226.tmp\Blink.cpp.o 
C:\Users\CROSSR~1.CRO\AppData\Local\Temp\build9182687107596139226.tmp\core.a -L
C:\Users\CROSSR~1.CRO\AppData\Local\Temp\build9182687107596139226.tmp -lm 
C:\Arduino\hardware\tools\avr\bin\avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 
C:\Users\CROSSR~1.CRO\AppData\Local\Temp\build9182687107596139226.tmp\Blink.cpp.elf 
C:\Users\CROSSR~1.CRO\AppData\Local\Temp\build9182687107596139226.tmp\Blink.cpp.eep 
C:\Arduino\hardware\tools\avr\bin\avr-objcopy -O ihex -R .eeprom 
C:\Users\CROSSR~1.CRO\AppData\Local\Temp\build9182687107596139226.tmp\Blink.cpp.elf 
C:\Users\CROSSR~1.CRO\AppData\Local\Temp\build9182687107596139226.tmp\Blink.cpp.hex 
Binary sketch size: 1,556 bytes (of a 258,048 byte maximum)

pins_arduino.h (9.2 KB)

How many Vcc pins do you make available?

When working with MCUs on breakouts like that, I feel like I never have enough Vcc and Gnd pins; if you’ve looked at my designs , you’ll note how I give 4-5 Vcc pins on each board, so someone can attach some basic components with jumper cables without having to bodge up some way to get more points to connect Vcc.

Have you considered an outline that could use a common HC/49 crystal? For most people, a strange surface mount 4-pin crystal is likely something they won’t have on hand (and they’re more expensive). Take a look at how I do pads for crystals - that will take through-hole HC/49, SMD HC/49, and those cute mini HC/49 ones (the .28"x.16" ones), as well as many 2-pin SMD crystals, or through-hole cans style. Of course, if you’re going to be selling it assembled only, this doesn’t matter so much.

I was suggesting a diode between +5 and GND.
i.e. cathode to +5V and anode to GND.
The diode in this configuration does not conduct, however, if some old man accidentally hooks power backwards, the diode conducts fully therefore taking out the power supply but protecting the 2561.

Looks very nice.
.

VCC is available near IC pin 20, 49, 64, the FTDI header, the ICSP header. I could make the 5V select jumper shorted by default (jumper pad with trace) then 2 more pads would be available full time. I could add another by the ICSP header, and one more in the upper right corner.

Diode from Gnd (anode) to Vcc (cathode). How hefty of a diode? 2A capable?
Something like that would be in SMB type package
http://www.digikey.com/product-detail/en/S2J-TP/S2J-TPMSCT-ND/773715
and have to go on the top of the board so the bottom could stay low height.
I’ll see if I can put it in the top right hand corner, give up the board name and move the mounting hole towards the edge more. Will have to beef up the power traces, can’t have them acting like fuses if power should be backwards.

Crystal - I wasn’t planning on offering this as a kit, so having place for HC49 type parts (or even the smaller XC1776
http://www.digikey.com/product-detail/en/ECS-160-20-3X-TR/XC1776CT-ND/2676640
which I have on the Bobweeny


would need to go on the top, requiring the board footprint to grow to make room for it.

This board will be used with limited output power supplies.
It would be great to have the diode survive an accident but, not necessary.
The diode could be considered sacrificial, replace it, if it shorts.
I am sure your experience is as mine, silicon diodes go short in a situation like I am suggesting.
This diode hopefully will never be used, only in an accidental situation, which may happen during experimental or inexperienced user applications.
The diode's function is to protect the hard to replace/unsolder and expensive 2561.
If nothing else, pads to accomidate it would be nice.
The diode you linked looks great, but a 1/2 or 1 amp package would work, may have to be replaced on a fault.

Edit:
I like beefy power traces. :slight_smile:

My guess is Bob will supply a finished product, the crystal selection is his choice not the end user.