Pages: [1]   Go Down
Author Topic: How to access unused pins on an atmega1280?  (Read 1093 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I've just put together a makeshift 'arduino mega 1280' on a TQFP100 breakout board, bootloaded it, and it's going fine.

There are a number of unused I/O pins on the arduino mega, ie. it has 54 digital I/O + 16 with analog, for a total of 70 possible digital outs, but the chip actually has 86.

So my question is, is there a way to get full access to the 86 pins through the arduino IDE?  If not, what kind of alterations might I make to make it possible?  Perhaps an addition to the hardware/arduino/variants/mega/pins_arduino.h file?

If anyone could point me in the right direction I'd be greatly appreciated.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"Perhaps an addition to the hardware/arduino/variants/mega/pins_arduino.h file?"
Yes.
There are 3 areas where the ports are listed, where the bit for the port is listed,  and whether the bit is on a timer.
So you need to start with adding the pins there.
There are some other places where the numbe of IO is listed, and some other stuff.  I can't follow all of it, troublle readig the cryptic undocumemted C code.
I'm also interested in accessing more pins, haven't gotten around to chasing all the changes down.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Perhaps an addition to the hardware/arduino/variants/mega/pins_arduino.h file?

That certainly is one way.

Another would be to use port access available in gcc-avr.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"use port access available in gcc-avr."
 
Can you explain how to do that and stay within the IDE?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,  thanks for your replies.

So for now, I'll try just adding a pin 70, on PJ2,  the unused pin 65 on the chip. I've added lines at the end of each of those three areas you mentioned.  It compiles and all, but I don't get a blink yet.

Perhaps it has to do with the defines part at the beginning of the file :

Code:
#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

Does anyone have any idea how to interpret the meaning of this?
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 72
Posts: 1641
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't need to worry about those lines unless you plan to use PJ2 as a pin change interrupt. However if you do, I have modified them for you:
Code:
#define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 13)) || \
                                  (((p) >= 50) && ((p) <= 53)) || \
                                  (((p) >= 62) && ((p) <= 69)) || \
 ((p) == 70) ? (&PCICR) : ((uint8_t *)0) )

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

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

#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
                                ( (((p) >= 50) && ((p) <= 53)) ? (53 - (p)) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
                                ( ((p) == 70) ? 3 : 0 ) ) ) )

---------------------------------------------------------------------------------------

In order to get a new pin to work, you need to do a several steps:
(1) at the end of this:
Code:
const uint8_t PROGMEM digital_pin_to_port_PGM[]
add this:
Code:
PJ , // PJ 2 ** 70 ** D70
This specifies which port the pin is on (in this case J)

(2) at the end of this:
Code:
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]
add this:
Code:
_BV( 2 ) , // PJ 2 ** 70 ** D70
This specifies a bit mask for this pin in its port (In this case it is the bitmask for pin 2)

(3) at the end of this:
Code:
const uint8_t PROGMEM digital_pin_to_timer_PGM[]
add this:
Code:
NOT_ON_TIMER , // PJ 2 ** 70 ** D70
This specifies that it is not a PWM output (which it is not)

(4) at the to, change this:
Code:
#define NUM_DIGITAL_PINS            70
to this:
Code:
#define NUM_DIGITAL_PINS            71
This tells the IDE there are now 71 useable pins not 70.

Then restart the IDE and try to run the code. It *should* work.
« Last Edit: October 14, 2012, 06:14:02 am by Tom Carpenter » Logged

~Tom~

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Tom,

Thank you very much for your detailed explanation!  By going through those steps I was able to add all the rest of the pins, and I've blink-tested that they all work.

Thanks again
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

kx,
Can you post that please?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

By 'post that'  I guess you mean my pins_arduino.h file for the mega?

I'll attach it to this message. It is to be placed in the hardware/arduino/variants/mega directory. You may prefer different placement of the pins,  but I just kept the original arduino mega pins, and went around the chip adding the missing pins to the end
from D70 till D85. An 86 pin Arduino for about $15, not bad eh?

Hope it's useful,

cheers

* pins_arduino.h (13.02 KB - downloaded 15 times.)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, that's what I mean. Thanks!

I have a couple of schmart boards and 2560 chips, planning to make a "standalone 2560" out of it. Add a crystal, caps, bunch of headers, be good to go!
This will make all the IO pins usable.
Now just need another 40 hours a week free for all my projects!
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 44
Posts: 2810
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

CR keep us posted on your progress I would likke to use all of a 2560 like you except for a dedicated board rather than your "Open Face" design. This kindergarten project og mine could really grow if I could move part of the GLCD. It would let me save my "Nice" 4D Systems 3.2 SGC for smoething better than this one... or maybe not.

Bob
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How would you layout such a dedicated board?
I have several designs in the works, but mostly for the serial ports availability. A lot of the IO is not used.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: