Where does one GET the funny mnemonic constant names?

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Forgive the basic-ness of the question, I'm a total newb. Looking thru peoples' examples, I see jillions of spiffy names used like OSC_FRQRANGE_12TO16_gc, SLEEP_SMODE_STDBY_gc, PORTCFG_VPCTRLB, etc. I can usually find where these names are defined in include files, and can usually track the definitions back to an MCU datasheet... But my question is - when one sits down to write this code, where does one FIND these names in the 1st place? It seems like each one involves finding the right needle in the right haystack, one at a time, and would take forever^2 to write a program! Am I missing some crucial piece of understanding on how to quickly identify which spiffy constant name to accomplish tasks? thanks, paul

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Programming a CPU always starts by reading a datasheet. Say you want to program a UART you'll find it maybe has something like 6 control registers. Of these perhaps four will have control bits that are again given names by Atmel. If things are working right the compiler developer will provide you na set of header files with the same names used to #define the numeric addresses and bit positions/masks. So it should be as simple as writing

FOO = 1 << BAR;

and those names in the C code should match the very names Atmel assigned in the datasheet. Of course there are issues when Atmel defines both masks and bit positions that they need to add a common suffix to differentiate one from the other.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmmm, still confused. Let's say I'm fiddling with the atxmega128a4u. So I'm looking at Atmel's iox128a4u.h that came with their "AVR 8-bit Toolchain version 3.4.4" - there's a definition (picked at random):

#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)

But I find nothing about this stuff in the Atmel datasheets "Atmel-8387-8-and16-bit-AVR-Microcontroller-XMEGA-A4U_Datasheet.pdf" or "Atmel-8331-8-and-16-bit-AVR-Microcontroller-XMEGA-AU_Manual.pdf". Can you clarify "the very names Atmel assigned in the datasheet"? thanks, paul

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TCE0_INTCTRLB is several different pieces of information. TC is a timer/counter. INTCTRLB is a particular register of a timer/counter. All timers/counters across the whole AU range are the same. Therefore, they are described in the AU manual (section Timer/Counter -> Register Description). The number of timers and their mapping to I/O ports is part-specific. Therefore, that (TCE0) is defined in the part-specific manual (A4U, in your case), in the Alternate Pin Function section.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For avr8, a program usually starts with a

#include 

, which in turn pulls in various files from avr-libc, depending on the setting of the -mmcu=xxx compile switch, which define all the symbolic constants for that chip.
Avr-libc creates the files either via hard work, or based on XML files provided by Atmel.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

paulofelora wrote:
#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)

But I find nothing about this stuff in the Atmel datasheets


You won't: because the datasheet is purely a hardware document; it describes the chip - not any other tools or software you may or may not use with it.

For details about the libraries, tools, and other software for use with the chip - you will have to study the documentation for the particular libraries, tools, or whatever

Quote:
Can you clarify "the very names Atmel assigned in the datasheet"

ie, the names - words - Atmel use in the datasheet.

eg, "INTCTRLB" may be the name that Atmel have given to the "Interrupt-Clear B" Register.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ezharkov wrote:
TCE0_INTCTRLB is several different pieces of information. TC is a timer/counter. INTCTRLB is a particular register of a timer/counter.

This is known as a Naming Convention.

It is a Convention for building the Names used within a piece of software.

In other words, it is a Convention - a set of rules - by which the Names are constructed from the elements of the thing they describe.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahhh, thank you all, gentlemen, the light is slowly coming on. When awneil talks about a "Naming Convention", I'm hearing something like this: the first piece is an "MCU component", say TCE0. Next, INTCTRLB, is the "Interrupt Enable register B" that controls TCE0. But then I get lost - this business of _SFR_MEM8 seems to exist only in the .h files for each MCU. Within each .h file there are many _SFR_MEM8 blurbs, each with its own constant. Searching around, I see that this _SFR_MEM8 is a macro "defined here to make the special function register definitions look like C variables or simple constants". I suspect this is where my C understanding gets a little thin, and westfw points me to the need to learn a bit about avr-libc... drilling down, down, down... thank you all! paul

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't need to worry about _SFR_MEM8() (it's in sfr_defs.h if you are really interested) all it's doing is converting a literal (the SFR address) into a volatile uint8_t pointer that you can read and write through.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks, clawson