Go Down

Topic: ATmega2560 bootloader to use more i/o pins (Read 9231 times) previous topic - next topic

linemouth

I'm new to the forum, I'm rather a novice at coding, and despite my exhaustive search, I have not found much information to help me. The Arduino MEGA Rev3 does not make use of all the I/O pins, and I want to know if it's possible to use all the pins (if broken out to headers), if a modified bootloader exists that utilizes all the pins, or how difficult it would be for me to make a modified bootloader myself. While I don't know much about the '2560, I've been teaching myself a lot about the '168/'328 series, and have built my own series of boards based on the pro-mini. Is this a simple matter of adding some methods in the source code using the physical pin addresses, or will it roast what little programming skill I have?

CrossRoads

The bootloader does not determine the IO pin usage.  That is defined in the pins_arduino.h file that goes with a board.
The bootloader only controls talking over the serial port after a reset to see if serial download will happen, or if the sketch will start up.
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.

linemouth

Okay. I've skimmed through the file, and I see some tables full of things that look like pin assignments, but I'm not sure how to interpret, let alone change, them. Any tips?

CrossRoads

In -0023, I would have confidently said yes.
In 1.0, I am much less sure.

A good start would finding the 3 sections where the pins are assigned.
The first assigns the port assignments to the D#s, starting  with D0 and working up.
The second assigns the bits of the port called out in the first, these can be in order, or they can be jumbled.
The third assigns whether the bit has a timer associated with it (so it can be PWM'd).

After that, more research is needed. Somehow the analog pins are assigned digital #s also, or maybe the other way around - the digital pin assignments are given analog numbers if they are the ADC inputs.

Hope that gets you started.
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.

iyahdub

With all respect, if you thought that the bootloader had any thing to do with pin assignment, then id advise you to do a lot of research first on the AVR way of working and coding, and the way the Arduino IDE works through it by minimizing our need to set it all !
10 LET Loop=Infinite
20 GO TO 10

CrossRoads

iyahdub, You are missing linemouth's intent.
The Mega does not bring out all the ATMega2560's IO pins. Only 54 of 82 or some similar quantity. The goal was to have access to more of them. One way to do that is to update pins_arduino.h so the rest are accessible from the IDE.
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.

linemouth

Okay, it looks like I've located the sections of pin assignments, and it's making vague sense. Now, it would be nice to have the pins in physical order instead of their port order, and I'm noticing that some pins have timers associated with them that aren't used. I also see that all four rx/tx serial ports use PWM (OSC[0..4][A..D]) pins- is this required hardware for the serial to work, or can any digital pin do the trick? On this graphic http://arduino.cc/en/Hacking/PinMapping2560, I see a mismatch- on the chip side, it has the four rx/tx ports scattered on all four sides of the chip, while the arduino pin map (red) has them grouped on the left edge. Does this say that those non-pwm pins can be used for rx/tx, too?

CrossRoads

The pin assignment go from D0 to D54. If you are making your own pins_arduinio.h  you can change the order however you'd like.
Whether a pin is connected to a UART and is PWMable is defined by the actual hardware, so have the ATMega2560 data sheet handy as you go.

I would agree, the stuff in Red on the top of that link appears to be a little off.
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.

iyahdub

#8
May 21, 2012, 08:44 pm Last Edit: May 21, 2012, 08:46 pm by iyahdub Reason: 1
Yeah i did miss his point then...Soz
Its good i did then, cause ill start a development of a project on a mega quite soon, and its definitely good to know that then !!
10 LET Loop=Infinite
20 GO TO 10

linemouth

Oh, hey! In pins_arduino.c, it says:
// ATMEL ATMEGA1280 / ARDUINO
//
// 0-7 PE0-PE7   works
// 8-13 PB0-PB5  works
// 14-21 PA0-PA7 works
// 22-29 PH0-PH7 works
// 30-35 PG5-PG0 works
// 36-43 PC7-PC0 works
// 44-51 PJ7-PJ0 works
// 52-59 PL7-PL0 works
// 60-67 PD7-PD0 works
// A0-A7 PF0-PF7
// A8-A15 PK0-PK7
That totals to 68 digital and 16 analog (84I/O), and the 128 is the same as the 256 in everything except for memory size, right? With this commented, I can basically just use these pins for I/O.

Now, the PWM timers- are they hardwired to particular ports/pins, or can they be assigned to operate on a specific pin?

CrossRoads

The hardware PWM timers are  hardwired (part of the ATMega chip architecture) to particular ports/pins.

It is possible to do software PWM as well, but that is not part of pins_arduino.h
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.

linemouth

Okay, I'm going through the datasheet and I'm mapping the capabilities of each pin. Once I do that, I should have a clear path to my goal. Thanks so much for the help!

iyahdub

Keep us updated later on then, if you dont mind of your finding, please !!
10 LET Loop=Infinite
20 GO TO 10

CrossRoads

I reviewed the schematic vs the pin mapping page, everything is in sync.
Some signal names are brought out to floating headers, with the schematic showing more clearly that TX3/RX3 are D14/D15 on the COMMUNICATION header, while the notes in Red on the mapping page are not so clear, and the mapping table Not showing them on physical pins 64/63 but instead has physical pins 14/15 (PH2/3) seeming to indicate they are TX3/RX3. So the Red Notes and the table could use a little cleanup.

They do agree (almost - pin 14/PH2 should be blank) that there are 16 pins available to be mapped.
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.

linemouth

#14
May 21, 2012, 10:53 pm Last Edit: May 21, 2012, 11:10 pm by CrossRoads Reason: 1
Not a problem!  :) In that previous message, the pins_arduino.c says that just about every pin is available for I/O, the exception being PB6 + 7. Why this is, I'm not sure, and these pins ARE used on the official MEGA. I'm pretty certain, then, that these pins can be used, giving us a total of 70 digital and 16 analog pins. Among the digital are four UART ports, one SPI port, one JTAG port, and I2C/TWI port, and several pins that can be used for an external parallel memory interface (16 address/data pins and three strobes). There are 15 pins with PWM connections, and the official MEGA uses RX0 and TX0 for PWM as well. It's strange, though, that pin 26 (PB7/ digital pin 13) has two PWM timers wired to it: 0A and 1C. Anyway, that's 17 PWMs that I can see, and only two of them coincide with communication pins (unlike the ATmega328, which uses half its PWMs for SPI pins. I've tabulated my findings so far below:

A couple things to note: there are 11 ports ranging from A-L, excluding I. Port G only has six pins.

A      Com      PWM      Int      I/O
PA0                        D
PA1                        D
PA2                        D
PA3                        D
PA4                        D
PA5                        D
PA6                        D
PA7                        D
B      Com      PWM      Int      I/O
PB0      SS      PC0      D
PB1      SCK      PC1      D
PB2      MOSI      PC2      D
PB3      MISO      PC3      D
PB4            2A      PC4      D
PB5            1A      PC5      D
PB6            1B      PC6      D
PB7            0A+1C   PC7      D
C      Com      PWM      Int      I/O
PC0                        D
PC1                        D
PC2                        D
PC3                        D
PC4                        D
PC5                        D
PC6                        D
PC7                        D
D      Com      PWM      Int      I/O
PD0      SCL            EX0      D
PD1      SDA            EX1      D
PD2      RX1            EX2      D
PD3      TX1            EX3      D
PD4                        D
PD5                        D
PD6                        D
PD7                        D
E      Com      PWM      Int      I/O
PE0      RX0            PC8      D
PE1      TX0                  D
PE2                        D
PE3            3A            D
PE4            3B      EX4      D
PE5            3C      EX5      D
PE6                  EX6      D
PE7                  EX7      D
F      Com      PWM      Int      I/O
PF0                        A
PF1                        A
PF2                        A
PF3                        A
PF4      TCK                  A
PF5      TMS                  A
PF6      TDO                  A
PF7      TDI                  A
G      Com      PWM      Int      I/O
PG0      wr                  D
PG1      rd                  D
PG2      ale                  D
PG3                        D
PG4                        D
PG5            0B            D
H      Com      PWM      Int      I/O
PH0      RX2                  D
PH1      TX2                  D
PH2                        D
PH3            4A            D
PH4            4B            D
PH5            4C            D
PH6            2B            D
PH7                        D
J      Com      PWM      Int      I/O
PJ0      RX3            PC9      D
PJ1      TX3            PC10      D
PJ2                  PC11      D
PJ3                  PC12      D
PJ4                  PC13      D
PJ5                  PC14      D
PJ6                  PC15      D
PJ7                        D
K      Com      PWM      Int      I/O
PK0                  PC16      A
PK1                  PC17      A
PK2                  PC18      A
PK3                  PC19      A
PK4                  PC20      A
PK5                  PC21      A
PK6                  PC22      A
PK7                  PC23      A
L      Com      PWM      Int      I/O
PL0                        D
PL1                        D
PL2                        D
PL3            5A            D
PL4            5B            D
PL5            5C            D
PL6                        D
PL7                        D

Go Up