How do I "use" an ATMega328 datasheet?

Do people read it like a book (all 660 pages)?

Are there people who understand the chip inside-out (all the components of the chip's architecture, how to program the chip to do something?

How do I learn about the chip's components and how they work together?

1 Like

Usually you look up the section you need review.

You really need a background in digital electronics and perhaps design.
You need experience in reading data sheets with more general/basic digital I.C.s
You also need some experience in more advanced programming.

You need to be geeky :wink:

How do I learn about the chip's components and how they work together?

Read, experiment, learn from examples, ask questions.

What is your background?

ElusivePi:
Do people read it like a book (all 660 pages)?

Yes, there might be as many as twenty people on Planet Earth who have done that. Five wrote it, five had to check the first five, and most of the rest had nothing better to do.

Are there people who understand the chip inside-out (all the components of the chip's architecture, how to program the chip to do something?

Possibly, but very few, and you can bet that the people who are best at programming it to do something are too busy doing things more worth their while than understanding the chip inside-out.

How do I learn about the chip's components and how they work together?

Do you really need to know that?

ElusivePi:
Do people read it like a book (all 660 pages)?

Of course not. That would be a waste of your time.

Are there people who understand the chip inside-out (all the components of the chip's architecture, how to program the chip to do something?

Those two are distinct / non-overlapping questions. Undoubtedly there are people who know AVR processors inside-out. There are significantly more people who know how to program the chip to do something.

How do I learn about the chip's components and how they work together?

Each chapter describes one subsystem / peripheral. The beginning of each chapter has an overview. The overviews are worth reading. You will learn what services the hardware provides.

As you delve deeper into each chapter the details become more specific culminating in register / bit descriptions. Unless you are actually programming that subsystem / peripheral those details are not worth reading.

Basically, when your eyes glaze over from boredom skip to the next chapter.

Hi,

What do you want to do with the microcontroller?
What is your electronics, programming, arduino, hardware experience?

Depending on what you want to do, will govern what parts of the sheet you need.

Tom..... :slight_smile:

When I am trying to understand how to use some part of the Atmega 328 datasheet I often find that enlightenment strikes after reading the relevant paragraphs 12 or 15 times.

So I would not be surprised to learn I have read 660 pages - just not every single page. Incidentally my copy only shows 448 pages.

Usually I read parts of the datasheet to fill in extra detail that is not obvious from the Arduino functions (e.g. changing the PWM frequency produced by analogWrite() ) or to figure out how to use features that are not part of the standard Arduino functions (e.g. the analog comparator).

Each section of the datasheet terminates with a description of the relevant Registers. All of those registers can be directly programmed from Arduino code - it "knows" the names of the registers (eg TCCR1B - bits 0,1 and 2 of that byte select the timer clock speed and hence control the PWM frequency )

For understanding the datasheet it would probably help to have a general understanding of how micro-processors work. I'm sure Google can find lots of suitable reading material.

...R

Typically, at least half of the atmel datasheets at the end is stuff you'll hardly ever look at (there are some electrical prop tables I've occasionally looked at).

I read the chapters on the peripheral I'm trying to figure out, and if possible also look at some example of code doing something kinda like what I'm doing. Don't read it aimlessly, you're unlikely to remember it.

TomGeorge:
What do you want to do with the microcontroller?
What is your electronics, programming, arduino, hardware experience?
Depending on what you want to do, will govern what parts of the sheet you need.

What I want to do with the uC is not really what's driving this question. I'm just curious about (1) who reads the datasheet, (2) what data they find relevant (what their intentions are when referencing a data sheet) (3) typical data flow that are a part of common uC operations (writes to prog mem, program execution).

I'm curious about (1) because I'm a "computer systems engineering" student (a program that combines courses from both EE and CS), aspiring to be an embed engineer. I'm also an electronics hobbyist.
We don't do double the workload (as one would if you double-majored) but, at the sacrifice of some depth, we gain a broader perspective of a system.

In particular, my core course load included:

  • Basic circuits analysis
  • Intro to the math behind DSP, DSP, & stochastic processes
  • Intro to digital logic & computer architecture
  • Some labs that required us to find info. on MIDI specs and exposed us to the workflow of programming an FPGA (we used a Terassic dev/edu board).
  • My course electives: Feedback of Dynamic Systems, Data structures & Algorithms, Algorithms (a more formal treatment of algorithms), Intro to CS Logic (the material that teaches you the fundamentals of how to think like a computer scientists that sets you up to write proofs)

With those courses under my belt, I can "identify" some elements in an ATMega datasheet but understanding how they work together is more involved, especially since the components aren't "broken out" and everything is hidden on a tiny 28-pin package. For the components that I can't identify, the datasheet does a good job explaining what they are but it doesn't provide examples of their use (like the "example" problems in a calc book).

TomGeorge:
What is your electronics, programming, arduino, hardware experience?
Depending on what you want to do, will govern what parts of the sheet you need.

Basic knowledge of electronics - enough to identify discrete components - but not really enough to "understand" the function of small (5-6 discrete components + some transistors) circuit topology, especially if they involve BJTs/MOSFETs. I can probably write an equation and draw you a plot of a voltage at some node in some circuit for a given driving input voltage but I'll likely make some mistakes.

I've written enough programs to understand the basic elements of a programming language (variables, scoping, control loops, program flow/functions, data structures, bit-operations, pointers, classes). C/C++, Java, Bash Scripting, Python (just started), Matlab (a little bit of DSP), little HTML & CSS, Processing. There are some "more advanced" fundamental topics about C/C++ that I haven't learned. I've heard of but don't know design patterns, code refactoring, organization, and website programming.

I think I'm a bit beyond using the arduino as a platform for "artists and beginners". I find myself more curious about the C/C++ code libraries that abstracts communication with the digital components on the ATMega.

1 Like

ElusivePi:
What I want to do with the uC is not really what's driving this question. I'm just curious about (1) who reads the datasheet, (2) what data they find relevant (what their intentions are when referencing a data sheet) (3) typical data flow that are a part of common uC operations (writes to prog mem, program execution).

I guess I am having difficulty understanding why you are posing these questions. I assume you are not going to suggest it was a waste of time for Atmel to write the datasheet.

Maybe another way to think about the role of the datasheet is to recognize how many things we use regularly without needing to read the instructions except in a very cursory manner - TVs, dishwashers, cars etc. This is because they all adopt a well established human interface which only varies slowly.

And, perhaps as a result of that, it is common for people to have an aversion to studying instructions - including, perhaps, Atmel datasheets. I'm sure there are many questions asked here which would have been unnecessary if the person had studied the relevant part of the datasheet.

It is impossible to use an MCU without following the very strict rules which it was designed to work by. And the datasheet provides that information.

The Arduino compiler encapsulates a lot of those rules in things like analogWrite(). (That could be considered the equivalent of the standard controls in a car). But the standard Arduino functions cannot encapsulate all of the options available in an Atmel MCU. Hence the need to refer to the datasheet for information about features of the MCU that are not part of the standard Arduino system.

And while you may be able to write many very effective programs using standard Arduino functions without ever needing to study the Atmel datasheet it is unlikely that you will be able to use peripheral devices with your Arduino without studying the datasheet for the device.

...R

For a hardware designer (e.g. the Arduino people and you), the hardware sections describing input and out levels, currents, frequencies and whatever are of interest. For you as the Arduino user because you need to know e.g. current consumption of the device, what are the output levels (e.g. can I interface with a 74HCT595), and so on.

For a software engineer (e.g. the gcc people) the functioning of every single piece of internal hardware as well as the instruction set is of interest; a lot of assembler programmers can dream it if they use it on a daily basis.

I used to work with MCS51 family devices as well as with PIC microcontrollers and basically could dream the assembler side of those (no C compilers available where I worked); bits in registers sometimes required a refreshing of the knowledge and designing the hardware always involved a reading to make sure that I did not exceed the specifications.

So yes, there are people that read (nearly) the complete datasheet if needed :wink:

1 Like

While I've overtly read most if not all of the documentation on a handful microprocessors and microcontrollers, the point of the Arduino ecosystem is that one can do physical computing without having to look at the atmega328 datasheet at all.

For someone with a technical background it is probably worth understanding generally what's in the document and in the chip because there are capabilities that are not fully exploitable at the pure Arduino level.

1 Like

Do people read it like a book (all 660 pages)?

Probably not. About half of that is "electrical characteristics", agonizingly repeated four times (for 48/88/168/328.) There might be things in that part that you need to look up, but it has a lot of diagrams and it probably isn't appropriate to read "like a book." Other things are repeated "per chip" as well.
On top of that, each section has a fair amount of redundancy. They'll describe how the peripheral is used "in general" and then have every register and every bit described in detail. Half explanation/description, and half "reference table."
That probably brings you down to about 100 pages of "readable material." That's doable. Especially if you skip the less interesting parts. :slight_smile:

Are there people who understand the chip inside-out (all the components of the chip's architecture, how to program the chip to do something?

Sure. Cliff on AVRFreaks. And quite a few people probably understand a lot of the chip, but have never used some particular aspect at the "bare metal" layer. I'm always a bit surprised when an otherwise "advanced programmer" wants to find somebody else's bootloader, for instance.

How do I learn about the chip's components and how they work together?

Practice. :slight_smile:

"comparative microcontrollers" is sort of my hobby. Here are some things I do when I look at datasheets:

  1. It really helps to have an idea what you want to DO with the chip. If it's got timers with 27 different modes, the real question is whether it has the modes that match your application, not fully understanding all 27 modes. The Arduino Core is a "pretty-good" target application, and I often look at a datasheet thinking "how would I use the features on this chip to implement an arduino?"

  2. Alternately, you can look at "what features does this chip have that are unusual or unique?" Again, timers are a good example - there are chips specifically targeted at motor control or switching power supply design that have special purpose features in their timers.

  3. One of the things to look out for is "additional reading required." The AVR data sheets are pretty complete; each one describes the AVR architecture and instruction set, at least partially. ARM based microcontrollers seem to be particularly poor, referring you to the "cortex M0+ reference", which in term refers you to the "ARMv6 architecture technical reference manual", and so on. (grr.) You don't need all that to understand the SAMD10 datasheet, but it IS a bit daunting to realize that there are 800+ pages NOT INCLUDING THE CPU ITSELF. Sigh.

  4. FEATURES. This is usually a nice short section of the manual highlighting the "important features" of the chip. This is where you start for noticing the "unusual" features that will need particular attention. Or areas that you can skip. (For example, I don't think I've ever done more than a quick skim of a DMA controller.)

  5. GPIO. How to twiddle/read the pins from software (digitalRead/digitalWrite); there's actually a surprising amount of variation here. And variation in names, too. ("io port" on AVR, "port" on SAMD, "pio" on SAM3x...) are there special purpose IO instructions? Special set/reset/toggle registers? pullups, pulldowns, etc? Are there byte-wide ports or wider? Can I modify single bits?

  6. Timers. I mentioned before that there are lots of types and modes for timers. Atmega8 has four different types of timers. SAMD10 has at least 5. SAM3x also has 5, but they're not the same as the SAMD timers. Which types are good for which functions (periodic timer, PWM. etc?) How many of each type? How many PWMs, and/or separate interrupts, can you get from each timer? How much flexibility in timing is there? (can you get a 1ms clock, or are you stuck with 1.024ms or similar? Do you have to share a timer between PWM and time functions (as on AVR Arduinos)? How fast can they clock? How slow?

  7. Serial IO. I'm especially fond of UARTs. How fast can the UART go? How accurate for common bitrates? How many UARTs? FIFOs? HW flow control? TWI and SPI are the other common serial interfaces. The AVR has separate UART, SPI, and TWI peripherals, but SAMD has a general purpose SERCOM peripheral that can be configured to do any of them. That means that a SAMD10 could do 3 UARTS, but then it wouldn't be able to do SPI or TWI at the same time. Or it could do three SPI interfaces and no UART. That's interesting, right?

  8. Program loading: how do I load software onto the thing? Does it need a special programmer? Is there a bootloader? Can I write a bootloader? What "special considerations" does bootloader support have/need?

  9. I probably should have mentioned this earlier, because it's increasingly important and annoying. Many of todays microcontrollers implement many more peripherals than they have pins to put the functions on. Which means that some functions will/might interfere with other functions. How do you control which functions are on which pins? Some chips have fixed pins for functions (but thos pins could have several different functions (like the Arduino analog inputs also being usable for digital IO)) Some have fancier "pinmux" settings where a particular function can appear at one of several sets of pins. Some even have the ability to move functions to pins relatively arbitrarily (Microchip calls this "Peripheral Pin Select" - Each pin can be mapped to any of 23 different peripheral functions!) (make yourself a nice table if one isn't supplied.) (recent annoying example: SAMD10 can't have as many PWM outputs than you might expect, due to pin conflicts.)

Um... I think that's about it. Pinout might be interesting. ADC, types and features of crystals, power-saving capabilities, EEPROM or equivalent(s). Interrupts and how "fine" they are (one interrupt per UART or separate RX/TX/Error/Modem interrupts?) ...

ElusivePi:
Do people read it like a book (all 660 pages)?

Are there people who understand the chip inside-out (all the components of the chip's architecture, how to program the chip to do something?

How do I learn about the chip's components and how they work together?

can you tell us the air to fuel ratio of your car, at an altitude of 1 kilometer and 34% humidity ?
what are the chemicals used in the composition of the floor mats ?
what color is the wire, what gauge, diameter of strands and thickness of the insulation on the wire that carries power to the door switch ?
the pages of the tome that is the data sheet of just one car, would fill a small library.
maybe, just maybe there is a person who knows a fraction of it.
did you know there is a specification on the hardness of the wire, the number of strands, the bend radius, for the wires that power the doors ? with a listed MTBF of door openings ?
what this means is that Lightning McQueen can win the Piston Cup and not need to know a small fraction of it.
if you want to drive a car, it does not matter
if you want to alter a car, then parts are there fore reference
if you want to make cars, then each crew needs that chapter.