Are there any forbidden registers or ports when using Arduino Mega 2560

Hi !

Got my 2560 yesterday which will be used as interface for my robot which runs with a PC and C# as platform. I have some years experience with uC a couple of years ago and at that time with Infineons C166 family.

20 minutes after opening the Mega 2560 box I hade evrything runing and both run the blink example and tested sending some data to the serial monitor. This is the easiest start ever with any uC :)

Now to my question: Before I start using timers and libraries which people have sent in as example I need to ask some questions which I didn't quite found any answers on while going through the initial material and guides.

  • When using the standard bootloader and development environment is there any timers, registers, ports that are occupied by the Arduino environment? Am I free to change as I wish? I will start setting up a timer with interrupt so I can have a easy scheduler running on different time-bases. Mybe use an example maybe use it myself.

  • Are there any files with all registers adresses available somewhere? When using the C166 we got a file with definitions on all registers so we did't have to define ports and their regsiters by ourselves.

In many of the examples I have seen som far the programmer have started defining the registers he wanted to use... There must be a definition file to include...or

Thanks/Fred

Freddan: Now to my question:

  • Are there any files with all registers adresses available somewhere? When using the C166 we got a file with definitions on all registers so we did't have to define ports and their regsiters by ourselves.

Hello Fred,

for your ATMega 2560 controller, you can find the information in file "C:\arduino-0022\hardware\tools\avr\avr\include\avr\iomxx0_1.h". So there's no need to define the register names yourself. You can also find some useful information in Atmel's datasheet for the ATMega 2560 controller in chapter 32 "Register Summary": http://www.atmel.com/dyn/resources/prod_documents/doc2549.pdf

Hope this helps.

Wolfgang

Timers, yes there are 1 or 2 used for timing (can't remember of the top of my head which ones). But you have several others to play with. Registers, you won't be dicking with them anyway will you? Ports, usart 0 is used for programming, you can muck with it but it's seldom worth the trouble.

Are there any files with all registers adresses available somewhere?

You shouldn't need the addresses, they have been "#defined" by file automatically included by the IDE. Use mnemonics like PORTB, TMSK0 etc. These can be found in the 2560 data sheet.


Rob

Timer0 is used to maintain the time for millis() and micros(). All timers are used for PWM (analogWrite()), and are initially in phase correct PWM at about 500Hz (except timer0 which is fast mode at about 1kHz) - however if you don't use the relevant PWM pins for a timer you are free to do what you like (and if you do you can change the mode/frequency if you are careful).

Some libraries use timers for various things - look to the library documentation in question (the Servo library does for one).