Go Down

Topic: Pin mapping a ATmega2561 (Read 10500 times) previous topic - next topic

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stank

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

CrossRoads

I think so, only differences are the signature bytes, and fewer ports.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stank

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

CrossRoads

Cool!

Can you make one up that does the same for a fully broken out 2560?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stank

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

przepro

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.

CrossRoads

'2561 only has 54 IO pins, 8 of which are the analog inputs on PORTA, See sheet 5 of the datasheet.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

yurislav

#23
Jun 29, 2014, 02:51 pm Last Edit: Jun 29, 2014, 04:48 pm by yurislav Reason: 1
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?

Cemoka

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


hansibull

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/
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

Cemoka

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 ?

hansibull

Pin 14 and 15 on the Arduino Mega 2560 has PCINT's, so it should work
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

Cemoka

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



CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up