Basic LED program

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

Hello, 

I have very limited experience with micro-controllers and C (astronomy masters student) and am wanting to use the AT32UC3C0128C to control some equipment on an experimental bench using the STK600 to program it in Studio 6. I have been trying to light LED0 on the board with no luck and am hoping for some help. 

I am trying to use the asf environment. I first tried using one of the installed templates -atmel board template STK600-AT32UC3C0512C and using the Led_On and Led_Off built in functions using the setup described below. Then I tried using the a user board template (UC3 C0/C1/C2) and the code below. In both cases, Studio 6 successfully connects to the device. When I enter into device programming I am able to read the voltage and device signature. I am using the on stk600 clock and set the clock to 125KHz. I then can successfully build the following code and load it to the mcu (the status led turns orange). Then nothing happens. From my code you can see that I am attempting to use GPIO 40 which is portB08 on the mcu and portF0 on the stk600 board. 

The only wires I have hooked up are the JTAG pins and the portF0 to the LED0 pin. I am powering the device from a battery and usb. 
Am I properly mapping the pins? Is there a major thing I am missing? 

I have been looking at various tutorials and atmel documentation online for the past few days but with no luck. Any help would be most appreciated. Thank you! 

 

#include <asf.h> 

int main (void)
{
board_init(): 

AVR32_GPIO.port[1].gpers=1<<8;
AVR32_GPIO.port[1].oders=1<<8;
AVR32_GPIO.port[1].ovrs=1<<8; 

while(1); 

}

This topic has a solution.

Last Edited: Sat. Jan 9, 2016 - 04:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

125Mhz?  I think you meant 125Khz, but I might be mistaken.

 

Did you connect a jumper wire from the GPIO port pin to one of the LED's pins?

 

There is a double row of pins with the words LED0, LED1, LED2 etc next to each pin and the word LED next to pins 0 and 1.  Pick a pin and place a jumper that came in the little plastic bag with the STK600 on the pin.  Then connect the other side of the jumper to the PORT pin associated with the GPIO pin you have used in your code.

 

WELCOME TO AVRFREAKS TOO! laugh

 

JIm

 

EDIT:

Can you post a picture of the STK600 and the routing/socket card you are using, and/or part numbers for them as well?  I am trying to look the gear up as well.

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Thu. Dec 24, 2015 - 04:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

maaikester wrote:
I have very limited experience with micro-controllers and C (astronomy masters student) and am wanting to use the AT32UC3C0128C to control some equipment on an experimental bench

Surely, just for equipment control, there are easier ways than diving deep into low-level 'C' coding?

 

I have been looking at various tutorials and atmel documentation online for the past few days but with no luck

So any specific reason(s) for choosing this particular chip?

 

It isn't exactly "mainstream"; wouldn't something more "popular" - and, thus, with wider community support - be easier?

 

 

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

maaikester wrote:
 I then can successfully build the following code and load it to the mcu (the status led turns orange). Then nothing happens. 

 

How do you know that nothing happens?

 

What were you expecting to see happening?

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

First set the data direction
PORTA.DIR=0XFF; // SET 1 FOR OUTPUT
PORTA.OUT= 0XFF; // all bit high of port A

KALARAV

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

Yes, I know it isn't exactly mainstream but I need one with four DAC channels to produce the necessary signal to drive a fast steering mirror (something I was doing via a DAQ card and MATLAB before) externally. 

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

Thanks for your answer. Yes I have a jumper wire connected from what I believe to be the correct GPIO port pin (GPIO 40 which corresponds to portF0 on the stk600 board) to the LED0 pin. 

 

The socket card/ routing cards are as follows: 

STK600-RCUC3C0-36

STK600-TQFP144

 

Oh and yes, sorry, I meant 125KHz. I will fix that asap in my post. I will also post a picture of my board.

 

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

Sorry, I should have clarified. 
 

I expect LED0 to turn on as it is configured to. This does not happen. 

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

Yes I have a jumper wire connected from what I believe to be the correct GPIO port pin (GPIO 40 which corresponds to portF0 on the stk600 board) to the LED0 pin. 

I think you may be wrong on the pin you think you are working with.

 

From what little I have just read in the datasheet for the device you are calling out,

AVR32_GPIO.port[1].gpers=1<<8;
AVR32_GPIO.port[1].oders=1<<8;
AVR32_GPIO.port[1].ovrs=1<<8; 

I am guessing that you are configuring a pin on the PORTB header on the STK600 since you are shifting 8 places.  I may be wrong as I have not done much with ASF.

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

 

jgmdesign wrote:

 

I am guessing that you are configuring a pin on the PORTB header on the STK600 since you are shifting 8 places.  I may be wrong as I have not done much with ASF.

 

 

From this link (http://www.atmel.com/webdoc/stk6...) and the mcu data sheet, I understand that GPIO 40 is on port 1 and is the 8th pin.

GPIO port = floor((GPIO number) / 32)
GPIO pin = GPIO number mod 32

This is PORTB0 on the mcu which corresponds to PORTF0 on the skt600 board due to the routing card I am using. Am I doing this correctly?

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

AS I said, I am not familiar with the UC3 devices, and ASF, but I am now confused as this:

GPIO port = floor((GPIO number) / 32)
GPIO pin = GPIO number mod 32

to me looks nothing like this:

AVR32_GPIO.port[1].gpers=1<<8;
AVR32_GPIO.port[1].oders=1<<8;
AVR32_GPIO.port[1].ovrs=1<<8; 

 

But yes, from your setup description, you are correct on the pinouts.  Can you post your entire ASF project so maybe someone can run it on their system or simulator?

 

Also, the consensus around here is that the UC family is not worth the effort.  Since you are in the early stages of your project, and your limited experience, have you considered using an AVR8 device? Or an ARM?

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Sat. Dec 26, 2015 - 02:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I went and created an ASF project on Studio6_2 and immediately realized that your code - at least what you have published WILL NOT WORK.  I did a project using LUFA and ASF and remembered that there is a lot of behind the scenes files you need to setup, like the I/O and the Clocks for example. 

 

THe line:

board_init(): 

Generates an error because you have a colon ':' at the end of the line as opposed to a semi-colon ';'

 

The code after:

AVR32_GPIO.port[1].gpers=1<<8;
AVR32_GPIO.port[1].oders=1<<8;
AVR32_GPIO.port[1].ovrs=1<<8; 

returns the warning:

Warning    1    input is not relaxable    src/ASF/avr32/drivers/intc/intc.o    0    0    ASFTEST
Warning    2    input is not relaxable    src/ASF/common/boards/user_board/init.o    0    0    ASFTEST
Warning    3    input is not relaxable    src/main.o    0    0    ASFTEST

 

WHich at this moment is irrelevant as you need to setup many other files in the background as I mentioned above.

 

I closed out the test project I created and grabbed one of the examples from the ASF library that is supposed to run on the STK600 and attached it to this post.  Now when I hit BUILD i received the same warnings on a couple of lines but if you look at the MAIN.c, you will see what's needed to perform a simple pin toggle like you are trying to achieve. Read the introduction in the MAIN.c file as it explains what the code is trying to do.   One of the functions is toggling an LED attached to a PORT PIN.

 

Point I am trying to make is to show you how complicated using this device is to perform even the simplest task.

 

Jim

Attachment(s): 

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

portB08 is GPIO40 so the AVR32_GPIO.port[1].xxxxx =1<<8 pattern is correct.
AVR32_GPIO.port[1].ovrs=1<<8; will set portB08 high but what does the STK600 require to light the LED ? a high-level or a low-level. ?

You could expand your while() ; loop with something like { AVR32_GPIO.port[1].ovrt=1<<8; followed by a time-delay }; to toggle the LED.

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

AVR32_GPIO.port[1].ovrs=1<<8; will set portB08 high but what does the STK600 require to light the LED ? a high-level or a low-level. ?

D'OH!!

The STK600 requires a 'LOW' signal to illuminate an LED.  GOOD CATCH!!

@mikech,

But aside from the STK600 active low, isn't there more to setting up an ASF project for UC3 than just the three lines of code we have seen from the OP?

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

Thank you for everyones response.

 

Yes it should be active low which means I need to change the last line to AVR32_GPIO.port[1].ovrc=1<<8 I believe. I have also attached the entire project. I am using an user board template  (UC3 C0/C1/C2) and following a tutorial (https://www.kth.se/social/upload...) which basically goes through different ways of programming an LED using different amounts of built in library dependencies. I am using the first method but without the switch part of the code. As I understand the template should contain all the necessary background setup for the asf. Is this correct? I have also attached my output when a built the code. 

 

I am also wondering if I need to set any fuses for JTAG programming or if I need to put any other initialization things in board_init? 

 

And for now I am stuck with my setup and don't really have the option to change. 

 

 

Attachment(s): 

Last Edited: Tue. Dec 29, 2015 - 10:17 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you everyone for all the posts. I finally got it working. Not sure exactly what it was but I took the assembly a part and put it back together which caused everything to work. I think it was one of the chip's pins wasn't connected to the skt600 properly. I now have interrupts working along with USART and am working towards getting the ADC/DAC working correctly (almost there)!

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

maaikester wrote:

Thank you everyone for all the posts. I finally got it working. Not sure exactly what it was but I took the assembly a part and put it back together which caused everything to work. I think it was one of the chip's pins wasn't connected to the skt600 properly. I now have interrupts working along with USART and am working towards getting the ADC/DAC working correctly (almost there)!

 

I have had a lot of issues using the STK600 boards and the UC3..especially with the ADC. I dont think the socket makes the best of connections with the pins, and i always had noise on everything i did. 

I ended up creating my own dedicated 'break out board / eval board" for this chip and those problems went away. 

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

maaikester wrote:

Thank you everyone for all the posts. I finally got it working. Not sure exactly what it was but I took the assembly a part and put it back together which caused everything to work. I think it was one of the chip's pins wasn't connected to the skt600 properly. I now have interrupts working along with USART and am working towards getting the ADC/DAC working correctly (almost there)!

 

OP, I was looking for some guide to get started with my project, and your post was very handy for me in 2017. Thanks for sharing your problem- it gave me a start/way forward- I have same board and similar mcu.

 

Did your final project succeed? I will like to ask your assistance on my project.