Go Down

Topic: Understanding "arduino.h" and "arduino.cpp" (Read 3353 times) previous topic - next topic

thexeno

... and others *.c and *.cpp files.
Hi!
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 :)

thexeno

Udo Klein

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.
Check out my experiments http://blog.blinkenlight.net

MarkT

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 <dist>/hardware/arduino/cores/arduino/*
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

thexeno

@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 :D

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

thexeno

MarkT

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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

thexeno

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? :)

Udo Klein

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.
Check out my experiments http://blog.blinkenlight.net

thexeno

#7
Oct 07, 2012, 09:03 pm Last Edit: Oct 07, 2012, 09:05 pm by thexeno Reason: 1
@Udo:
ok, I get it.. and thanks :)
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. :)

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

thexeno

AWOL

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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Udo Klein

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

http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial

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 ;) ). 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.

Check out my experiments http://blog.blinkenlight.net

thexeno

@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 :)
PS: if I'll find something, I will write here :)

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

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

thexeno

AWOL

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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Udo Klein

Quote
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.

Check out my experiments http://blog.blinkenlight.net

thexeno

@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.

Go Up