## [TUT] [SOFT] [HARD] AVR-C Reference Guide, EE, Programming

10 posts / 0 new
Author
Message

AVR-C Reference Guide:
http://www.jordanrejaud.com/blog...

Electrical Engineering/ Programming tutorials:
http://www.jordanrejaud.com/lear...

Hullo, I've started writing AVR-C tutorials/ reference guides (in a sisyphian attempt to have the quantity/ quality of AVR and "low level electronics" tutorials be as much of a plethora as Arduino tutorials) and aggregating electrical engineering, programming, CS, ect. tutorials and putting them in an order to help neophyte engineers learn new interesting things :)

Robotics Engineer and Android Developer

http://www.jordanrejaud.com

Nitpickin: Your

Quote:
PDn: AVR-C Library "shortcut" for pin number n

should perhaps be
Quote:
Pxn: AVR-C Library "shortcut" for pin number n

since there are pin number definitions for all PORT/PIN/DDR registers (x= A, B, C, D...).

It is true that PA1 == PB1 == PC1 ... (all "1"), but not using the same letter for the pin number as for the PORT/PIN/DDR makes for slightly confusing code, e.g.

`PORTA |= 1<<PD3;`

which would better be written

`PORTA |= 1<<PA3;`

Some might even prefer, for the digital I/O registers to simply code the number directly, like so

`PORTA |= 1<<3;`

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Also you say to use |= and &=~ for setting DDRs? But that's bad advice. Those you almost always set all 8 bits at once in a single assignment not using OR/AND.

Also how can you know what REF the user really wants? IF it was always to be REFS0 then Atmel would not have bothered to give us REFS bits to select!

There's a typo where you mention delays in that the closing > is replaced by its HTML code.

Oh and the timer stuff is close to useless. It's very difficult to write a timer tutorial because there's so many ways people may want to use them you can't cover all the options. Just setting CS bits then reading TCNT is probably never really used in fact.

To be honest the 101 thread covers bit manipulation better and the other stuff is too simplistic to be of much use.

Oh and tutorials here should contain the text in the first post - either as body text or, if formatting is required, as an attached PDF. If you just link to some other website the tutorial dies in 3 years when you stop hosting at that location! (this has happened many times here). At the very least put your text into a PDF and attach to the first post.

The points that Cliff made are because the page shows what the Arduino functions are doing under the hood. Since this is "After Arduino" it would be much more useful to show what you could do with it rather than show how to mimic the restrictive Arduino functionality.

Regards,
Steve A.

The Board helps those that help themselves.

Quote:
The ATMega328p is manufactued by Atmel and is (sic) programmed in the C language.

'C' is just one (OK, maybe the commonest) language in which it can be programmed.

Quote:
there are not as many tutorials to programming ATs (sic) and using C

You mean, programming AVRs :?:

Quote:
An Arduino board (like the Arduino Uno) isn't a microcontroller, but rather an electronics prototyping platform that contains a microcontroller.

Indeed: http://www.element14.com/communi...

8)

Jonah:
You are absolutely right, I don't see how something so obvious slipped by. I'll fix it.

Awneil/ The black cat:
Both good points

I'll update those sections accordingly.

Clawson:
Why would I set all my pins in a DDR register at once? What if I want one pin in that register to be an input and another one to be an output?

I do repeat myself twice in the ADC read... let me check why I said that and see if its a typo or I am misunderstood genius.

Good eye on the delay typo.

My intent is for this stuff to be simplistic and offer a "stepping stone" from Arduino boards/ the ostensible Arduino "language" to more sophisticated embedded electronics. I find that Arduino tutorials are very well written and numerous, thus very accessible to a high number of people.

"lower level" work isn't as easy to wrap your head around and the quantity and ease of comprehension pales in comparison to the Arduino world. My intent is to "enlighten" the masses and offer a route to better comprehension of low level embedded electronics.

Thank you for the feedback, I'll update the tutorials soon.

The reason I didn't throw my stuff into a doc file and just throw it into a forum post is because as my html/css/js knowledge grows, I want to continue changing the aesthetics of my site/ reference guides to streamline them and make them easier to understand (like https://learn.adafruit.com/adafr..., for example).

Robotics Engineer and Android Developer

http://www.jordanrejaud.com

Quote:
What if I want one pin in that register to be an input and another one to be an output?
The input pins do not need setup, just the output pins. (unless you had previously set the pin as output and then you need it to be an input ie for bit banged TWI/I2C).

`DDRA = (1<<PA7 | 1<<PA3 | 1<<PA0)    //Set bits 0, 3 and 7 as outputs, the rest are inputs`

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Quote:
Why would I set all my pins in a DDR register at once?
Because it saves lines of code. You can set all 8 bits with 1 line of code instead of 8. It also ends up being 2 cycles instead of 16 (or 3 cycles instead of 40 if the register is outside of the range of SBI/CBI).

Regards,
Steve A.

The Board helps those that help themselves.