Understanding "arduino.h" and "arduino.cpp"

... and others *.c and *.cpp files.
I would like to know what are all the default settings of registers in Arduino (Duemilanove rather than Uno). I.e. when I play with the serial interface, I know that even all other registers (in such like settings of PWM, Timers, prescalers) are setted in a way which differ from the default values automatically setted from the MCU itself, by the action of the all Arduino libraries loaded in the flash.
With this introduction, I ask to everyone if I can read these defaults values from somewhere pdf/site instead of reading all the source files. I tried to search for something, but I didn't find something that can inspire trust.

Thanka a lot, and I'm sorry if it's a stupid question :slight_smile:


Well, they say "the truth lies in the code". If you want trust that's the way to go. IMHO the code is easier to read if you are looking for defaults than any documentation.

Since different versions for different processors are different, the code itself is the place to look - its open-source, this is one of the reasons that’s a good thing. Just grep the relevant register name in /hardware/arduino/cores/arduino/*

@Udo: Thanks. But there's no documentation released by some developer?
I try to explain myself: in these days I started to study how to program my Atmel by using Atmel Studio (or C ide equivalent like Code::Blocks). Everything ok, but since I realised that the arduino libraries are setted in all details, in some cases I can use them by Wiring. That being said, the datasheet whith registers is slightly less than a thousand pages: comparing every settings in code with every page it can take forever. If someone has done this before (the Arduino developers), it can be useful if I can find something like "PWM are in phase corrected mode by default" rather than "the ninth bit in serial has been disabled" and so on for every settings.
I'm quite sure that there's something written (excluding comments in the code, lol) because all of this it's a huge work and I doubt that there's someone who makes this basing all on his memory -off by heart-.

I remind to you that this is only for my personal curiosity (and that should be like that for every one: we're all in a hobbistic/academic environment :D), related to the "1,8 Kb of code loaded" for blinking a led (instead of 400 bytes using normal C), just to know what are in a detailed way :smiley:

@Mark: you're almost right, but I still hope in something of a better docs :smiley:


Well thinking a little more, what would be useful (and less fragile) would be docs explaining where in the source tree each hardware interface in the MPU is setup and how it is used... This is much more consistent across different versions, less likely to go out-of-date and would be a useful aid to self-instruction in itself.

Yes Mark, that more or less it is what i'm talking about.
It can be even useful for those people who try to start using the real C. Isn't Arduino an academic project too? :slight_smile:

There will be no one who will be willing to write such a documentation. Those that are capable also know how to use tools like "find", "grep" and similar. Once you know this you will see little point in writing up such a documentation.

BTW: the whole core code base of Arduino is pretty small. You can read it within a day.

ok, I get it.. and thanks :slight_smile:
Let me explain one other concept around this: ok, I'll read the whole core and ok, I see what are all parts setted (i.e.). But for every settings, I have to check on the datasheet. To understand very well the PWM (all modes of operation, all exceptions and how are they handled) it takes a day or even more (because when you try to write code not always it works, and for that reason I wrote a little doc file, a draft, where I noted all combinations and their exceptions. In this way, further codes are written in an easily way). Now think if you should do this for everything.
What the Arduino does, it's the same work to categorize all functions in object of C++ (that I done for PWM in a text file) and reuse them in an affidable and clearly way. So, even if you read my document, if you don't have a datasheet, you will not understand.
BUT IF you would know simply "oh, cool, my led fades: what's the default frequency and what its default phase and interrupt modes?" if the answer will be "you should read the configurations adopted and, after you understand the code, then you should see in tables what are those registers setted", it's different from "you have to know what you are using because it's not written by you, so: the frequency by default it's 490Hz, phase-corrected mode, interrupt on top disabled. BUT if you would like to change it, let's start to study".
Now I shown to you an example of what I looking for, and I try to explain why understand the code it's only the 50% of total work, specially for people like me who don't are experts in AVR MCUs.

I hope to make the main idea.

Maybe in books written for Arduino it's probably written something about that. And the other thought was on WHAT it's loaded when I simply blink a LED (it's more than twice, and more than twice of twice when I set the serial interface). I can't understand it, maybe it's written somewhere? Because if I can't find those infos,for my purposes all the Arduino.cc became useless and I should start to study the case in a professional way, which is don't the case. And all for the only reason that they aren't able to tell me what are things that they had written. It's hard to believe to me. :slight_smile:

PS: can you tell me a books title or documentation which talk about this?


The size of that last post would go a long way to providing a decent sized documentation of the sort of detail you want on PWM.

Actually there is some kind of such in depth information. Unfortunately not for Arduino and not in English. It is found here:


If you want to go the "professional" route: learn how to build from the command line. Learn how to use the Arduino libraries without the "setup" and "loop" but with "main". Learn about version control (git recommended :wink: ). Once you have this in place I am pretty much sure that you will not need such documentation anymore. And you will understand why nobody will write it. I would bet that you will not write it as well.

BTW: my book is an attempt to guide people along these lines. However it is in German. So probably not that relevant for you.

@Udo: well, I understand what you mean. Since few months I started programming Arduino by using Atmel Studio. Simple stuff, using interrupts, PWM, and I started recently using the UART module. But because I don't always have the intention to program with more optimisation so occasionally I use the Wiring. But when you start using pure C, coming back at Wiring without knowing what is working at the bottom of the system it's really annoying for me. And in that moment comes out the intention to study the C++ and Java staying at the base of Wiring. But I can't stand doing it by my self and it's difficult too, because I'm not really interested at the software. (I'm studying electronic engineer (not informatics), we have done few courses about programming Freescale MCUs, and since that day I started using Atmel Studio or CodeBlocks for my Arduino projects).
Anyway, thanks Udo :slight_smile:
PS: if I'll find something, I will write here :slight_smile:

The discussion is still open for everyone who has the same thought.

@AWOL: I don't understand the goal of your sentence.


The "goal" was to point out that you expended a lot of effort in complaining about the state of affairs, when, perhaps, the effort might have been better directed.

I can't stand doing it by my self and it's difficult too, because I'm not really interested at the software. (I'm studying electronic engineer (not informatics),

In the end I assume that engineers and not the informatics guys will code Verilog/VHDL. For microcontrollers I am not quite sure but I assume it is also more something for engineers. But I am pretty much convinced that if you want to go for hardware development then (software) implementation skills are beneficial nowadays.

@Udo: yes yes, of course! But turning again on Arduino, I do this at home, with an hobbistic passion of an aspirant engineer. It's a simple MCU, if there is more docs about the software, it can be useful. After all, the Arduino project is the same to buy a super-mega-modded-gamer PC for using the incorporated webcam to snap a photo. The whole complexity is justified by the simplicity in mcu software development ("..Arduino it's for artists and for beginners who just started.."). It's a huge project, re-using environments like Processing, Wiring, C++, Java... neither an informatic engineer can't understand this well without a documentation. And I'm not interested to know the background of Wiring (writed in Java) keeping alive the Arduino project, but only the final stage, that one which send files to avrdude program. And how work the toolchain.

For who is still looking try this one :

How is ArduinoCore-avr/wiring.c at master · arduino/ArduinoCore-avr · GitHub
And nearby code not what you’re looking for? It tells you about the pwm mode ,tells you what the prescalers will be, and has the other bits needed called out as well. True, it doesn’t decried all the bits left off, but that’s rarely done outside of tutorials and class assignments for especially fussy profs. (And it becomes rapidly impractical on even moderately complex peripherals. You are expected to use both code and data book to fully understand.

the frequency by default it’s 490Hz, phase-corrected mode, interrupt on top disabled. BUT if you would like to change it, let’s start to study".

I don’t know if I’ve ever seen that level of documentation for a piece of software that wasn’t explicitly designed as an educational example. It tends to lead to a rabbit hole of details that really aren’t that useful or interesting. (For example, for your PWM example, it would be really uncommon to say “I disabled interrupts”, instead documenting cases where you turned interrupts on. And the 6 PWM outputs of an Uno are distributed across 3 different timers, each of which is configure slightly DIFFERENTLY (timer0 also generates the millis() interrupt. Timer1 is a 16bit timer…) And of course it’s all likely to be completely different on a different CPU (Nano Every has different timers; Due has a special PWM peripheral.
I think your question is sort-of like “I want to learn all about physics without having to do math.” Eventually, if you want to learn about the Arduino PWM modes, you MUST learn about the chip timer details.

Please note that a Nano Every did not exist when this thread was started 7 years ago :wink:

I'm too young to know if the same applies to the Due :wink:

Ah, crap. Didn't notice the necromancy... :frowning: