Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
jrejaud
PostPosted: Jul 02, 2014 - 12:26 AM
Newbie


Joined: Jul 02, 2014
Posts: 3


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

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

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 Smile
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Jul 02, 2014 - 04:28 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21982
Location: Lund, Sweden

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.
Code:
PORTA |= 1<<PD3;

which would better be written
Code:
PORTA |= 1<<PA3;

Some might even prefer, for the digital I/O registers to simply code the number directly, like so
Code:
PORTA |= 1<<3;

_________________
"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]
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Jul 02, 2014 - 09:51 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 71119
Location: (using avr-gcc in) Finchingfield, Essex, England

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.

When making an ADC reading you seem to be suggesting to always set ADSC twice??

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.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Jul 02, 2014 - 03:46 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 14996
Location: Vancouver, BC

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.
 
 View user's profile Send private message  
Reply with quote Back to top
awneil
PostPosted: Jul 02, 2014 - 07:02 PM
Posting Freak


Joined: Jul 02, 2005
Posts: 1116
Location: Basingstoke, Hampshire, UK

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 Question
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
awneil
PostPosted: Jul 02, 2014 - 07:13 PM
Posting Freak


Joined: Jul 02, 2005
Posts: 1116
Location: Basingstoke, Hampshire, UK

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

http://www.jordanrejaud.com/blog/afterarduino.html

Indeed: http://www.element14.com/community/road ... ment-18574

Cool
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
jrejaud
PostPosted: Jul 02, 2014 - 11:59 PM
Newbie


Joined: Jul 02, 2014
Posts: 3


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/adafruit-ard ... reversing, for example).
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jul 03, 2014 - 04:16 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 22556
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

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

Code:
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
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Koshchi
PostPosted: Jul 03, 2014 - 03:59 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 14996
Location: Vancouver, BC

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.
 
 View user's profile Send private message  
Reply with quote Back to top
jrejaud
PostPosted: Jul 04, 2014 - 06:07 AM
Newbie


Joined: Jul 02, 2014
Posts: 3


Fixed some of the more glaring typos...
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits