AT32UC3L0256 Gettnig started.... argh! [SOLVED]

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

I'm using my first AVR32 chip AT32UC3L0256 And I'm finding it REALLY hard to get into.

I've had loads of luck with ATMEGA, TINY, PIC et al, but for some reason I just can't find any consistent "getting started" for this chip class, tons on AVR though.

 

Firstly, I was lead down what looked like a wrong path from the official getting started guide

 

elde.cz/datasht/AVR32119 Getting Started with AVR32 UC3A Microcontrollers.pdf

Links there are broken, so I guess this is a little old?

 

The code examples just don't match up with whatever includes I'm getting in Atmel Studio 7

 

The guide says, for example:

AVR32_PM.oscctrl0=AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3<<AVR32_PM_OSCCTRL0_MODE_OFFSET | 3<<AVR32_PM_OSCCTRL0_STARTUP_OFFSET;

 

But that won't compile. With a lot of guessing and reading the datasheets I discovered this should be:

 

AVR32_SCIF.oscctrl0 = {yadda yadda other labels were different}

 

NOT in AVR32_PM as they said!

 

Some lovely and very helpful examples on how to use delay_ms() so that I can get my blinking light also ran into file not found on compile.

https://stackoverflow.com/questions/36571278/beginner-avr32-turn-on-led-compiler-does-not-see-variables

 

After some struggles, I can get an led to turn on at PB08 (port 32) with

 

#include <avr32/io.h>

:

AVR32_GPIO.port[1].oders = 1 << (0 & 0x1F);        

AVR32_GPIO.port[1].gpers = 1 << (0 & 0x1F);

AVR32_GPIO.port[1].ovr=1<< (0 & 0x1F);

 

Yay! But I'm seriously not getting the code-love that I got on the ATMEGA, where all the libraries just 'worked' off the bat.

 

So, this leads me to think that I just don't have the right includes / libs installed in Atmel studio… or I'm just being super-dumb and missed reading something extra basic. I just updated my Atmel Studio including AVR32 support which I hoped might help.

 

My includes seem to be at C:\Program Files (x86)\Atmel\Studio\7.0\packs\atmel\UC3L_DFP\1.0.59\include\AT32UC3L0256

 

Where am I going wrong??!! Do be kind with the RTM comments :)

 

Peace.

Last Edited: Sat. Aug 17, 2019 - 11:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
AVR32_PM.oscctrl0=AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3<<AVR32_PM_OSCCTRL0_MODE_OFFSET | 3<<AVR32_PM_OSCCTRL0_STARTUP_OFFSET;

Space cost nothing and make code more readable:

AVR32_PM.oscctrl0 = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3 << AVR32_PM_OSCCTRL0_MODE_OFFSET | 3 << AVR32_PM_OSCCTRL0_STARTUP_OFFSET;

but do you know (offhand) what the operator precedence rule in C is? I don't but I strongly suspect that line will not be evaluated in the order you think. To make it clear to the compiler I would use:

AVR32_PM.oscctrl0 = (AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3 << AVR32_PM_OSCCTRL0_MODE_OFFSET) | (3 << AVR32_PM_OSCCTRL0_STARTUP_OFFSET);

That code may still be "wrong" but it has more chance of succeeding.

 

Coming to this:

AVR32_GPIO.port[1].oders = 1 << (0 & 0x1F);        

AVR32_GPIO.port[1].gpers = 1 << (0 & 0x1F);

AVR32_GPIO.port[1].ovr=1<< (0 & 0x1F);

Anyhting ANDed with 0 is 0 so I wonder what the 0 & 0x1F in these is supposed to achieve? This code would have the same effect if you simply wrote:

AVR32_GPIO.port[1].oders = 1;        

AVR32_GPIO.port[1].gpers = 1;

AVR32_GPIO.port[1].ovr = 1;

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

Yeah, the readability... just copied that directly out of the guide PDF and I tend to write neater code than that - but that' not my problem.

 

The 1 << (0 & 0x1f) bit, I just left in as a reminder so that I can change the port easily for other IO. I try to avoid absolute values wherever I can and that'll all be in defines later as I get going.

 

Thanks for the first respone though!

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

Okay, so I think I have figured it out. I'm pleased that it was just something STUPID rather than long, complicated and painful.

It came to me at 2am after I'd settled down with some beers and episodes of Rick and Morty and a fresh installation of Atmel Studio on my laptop.

 

ASF! That's the answer. Start up a new C project, fire up the ASF wizard (chose user board 'cos i'ts my own hardware) and just choose the modules that you want.

 

Ba-da-bing! All the functions that I want are all at hand with self-completion, help, documentation.

 

Just FTM TLDs to take in al lin one go.