New to AVR and need some help with PINx_bm etc

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

Hello,

 

I've been programming arduino for a few years and now moved into AVR, bought a book on programming the 328p and gradually working through that. So pretty basic at present.

 

I have a project for which I need 4 uarts, so looking at the Microchip site, the 4809 chip seems to fit the bill. I have looked at the sample code for blink led and it uses the following statement:

 

PORTB.OUT |= PIN5_bm;

 

which is fine, I get the idea, but my question is where is  PIN5_bm (and I guess many others like it) defined? How do I get to see the definitions?

 

My other question is 'can I programme the 4809 chip with an AVRISPmkII'? (this works for programming my 328P)

 

Apologies for numpty questions, but I'm just starting out...

 

many thanks for help

Paul

Paul

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

Welcome to AVRFreaks!

 

paulskirk53 wrote:
where is  PIN5_bm

It will be in the part specific header linked to by io.h

 

as for:

PORTB.OUT |= PIN5_bm;

 

that is the same as PORTB.OUT |= (1<<5);  it just take some getting used to now, after learning and using (1<<n) for so long!!!

 

paulskirk53 wrote:
can I programme the 4809 chip with an AVRISPmkII'

No, as it uses UPDI rather then ISP for programming, the good news is you just need a curiosity 4809 which has built in both a programmer and a debugger (yea) and is recognized by MC7 when you plug it in!

https://www.microchip.com/Develo...

Only $15 and is bread board ready!

You can break out the programmer/debugger for use with other updi chips in the family too.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Wed. Feb 3, 2021 - 02:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://www.avrfreaks.net/forum/...

 

EDIT

 

Summary of the _bp, _bm, _gc, etc naming convention: https://www.avrfreaks.net/commen...

 

See Application Note AVR1000 - Getting Started Writing C-code for XMEGA:

 

https://ww1.microchip.com/downloads/en/AppNotes/doc8075.pdf

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...
Last Edited: Wed. Feb 3, 2021 - 02:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks very much for this, much appreciated.

Paul

Paul

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


paulskirk53 wrote:
which is fine, I get the idea, but my question is where is  PIN5_bm (and I guess many others like it) defined? How do I get to see the definitions?
As I said in another thread only yesterday (tutorial I wonder?) the way to quickly get to definitions is to just build a program, any program, can be the "empty" program as long as it will build successfully and when you have done that the "Dependencies" section shows the whole list of .h files that were found while the program built (Oh I forgot to say you will want "#include <avr/io.h>" as a minimum...

 

You now have a list of all the "standard" headers used in a minimal 4809 build (well, as I say one that include io.h). You can click any in that list to have a wander around inside their contents. If you want to know where any particular file "lives" then highlight it in the list then select the "Properties" tab:

 

 

And that will confirm the actual copy used (as I have several "packs" installed I have several copies of iom4809.h on my machine but this tells me it's the one in pack 1.4.351 that is being used).

 

The other thing to know about (if you don't just want to read through all those Dependencies files in turn) is that if you write something like:

 

and right click on "PIN5_bm" then this right click menu has the very useful "Goto Implementation" on it (first entry in fact) and when you do that it goes to:

 

which confirms that for this build the definition of PIN5_bm was supplied by iom4809.h (actually this surprises me - as it's going to be generic for most AVRs and certainly all the Xmega chips I would have expected it to be in portpins.h or xmega.h - you live and learn!)

 

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

Since all of these are generated register/bitfield defines from the atdf, generalizing or using portpins.h doesn't help much. As far as I remember, portpins.h only has the really old PXn defines left for backwards compatibilty... 

:: Morten

 

(yes, I work for Microchip, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

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


thanks, that's really useful. I'm using studio 7 (v 7.0.132) and I tried your process on this code snippet (from a microchip example)

 

 while (1)
    {
        if (~PORTB.IN & PIN2_bm) /* check if PB2 is pulled to GND */
        {
            while (~PORTB.IN & PIN2_bm) /* wait until PB2 is pulled to VDD */

but when I right click as per your post I get this context menu:

 

 

which doesn't include 'goto implementation'.

 

I probably missed something...all my chip related code now has red squiggles too, I probably need to select a chip from somewhere?

 

thanks

Paul

Paul

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

that probably means your cursor wasn't on anything that has a definition?

 

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


You have to position the cursor on the actual thing you want to see the definition of first. For example when I used it above I had:

Note that the cursor is in the middle of the symbol (which is therefore highlighted in cyan). If I positioned the cursor within "OUT":

(pink this time - there's probably some method in the pink/cyan madness!) then this time Goto Implementation takes me to:

 

 

while if I had the cursor in "PORT":

 

 

(back to cyan - well what do you know?) then this takes me to:

 

 

and so on....

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

thanks Guys - yes my cursor is placed in the item of interest (PIN2_bm) when I right click.

 

any code related to the chip has red squiggles e.g. code like this:

 

    PORTB.DIRCLR = PIN2_bm; /* set PB2 as input */
    PORTB.DIRSET = PIN5_bm; /* set PB5 as output */
    PORTB.PIN2CTRL = PORT_PULLUPEN_bm; /* enable internal pull-up */

if I hover my mousepointer over any keyword I get 'unrecognised sysmbol Alt G to Jump to a guess or let intellisense try'  If I try ALT+G it does nothing.

 

Do I need to specify a chip in atmel studio ? I thought that would be easy to do (having been used to pick a board and a port in Arduino), but I can't find a menu which does 'pick a chip'

 

thanks for help and sorry to be a pain.

 

 

Paul

 

Paul

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


paulskirk53 wrote:
Do I need to specify a chip in atmel studio ?

That's one of the first things you do as part of the 'create new project' process

 

EDIT

 

from clawson's screenshot in #5:

 

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...
Last Edited: Wed. Feb 3, 2021 - 06:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


What shows here?   Click it and change chip if needed, you may have to load additional chip packs for the newer AVR's

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

ki0bk wrote:
Click it and change chip

Does that work?

 

ISTR having to start a new project to get everything properly lined-up for a different chip?

 

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

ok, thanks I have the chip showing in the toolbar now and the right click context menu has the 'goto implementation ALT+G' option. (I did File > New> project and got offered a list of chips).

 

I can experiment a bit now.

 

thanks to everyone for help with this.

Paul

Paul

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


awneil wrote:

Does that work?

 

ISTR having to start a new project to get everything properly lined-up for a different chip?

Yes that works - for questions here I always use exactly the same AS7 project ("test" for C, "newtest" for C++). I just go in and use "change device" to target the right one. What I have noticed is that if you have had it set to several different devices the "intellisense" (or whatever it is in AS7) caches header info. So if you then have a symbol like "PORTB" and right click to "Goto implementation" it then maybe lists iom328p.h, iom644p.h, iom128.h as multiple possible locations because previously the project has been set to all three. Even though I have recently set the project to "mega328p" and had a successful build (at which point I sort of expected it would have forgotten about the previous mega644and mega128) it hangs onto them. In Visual Studio you can force it to reparse the intellisense header scan but I haven't yet spotted the way to do that in AS7.

 

Actually I just thought of a way! At the solution level there is an auto-created ".vs" directory and that's where the parsing data is held. Deleting that directory (while the solution is not loaded!) should force it to forget. Off for a quick experiment...



EDIT: OK before I tried that I thought "there must be a way that I'm missing". So I trawled the menus and found:

 

 

Having done that it does seem to have "forgotten" previous device headers.

Last Edited: Thu. Feb 4, 2021 - 09:38 AM