Blinking a led on AVR - works with avr/io.h, not with ASF - Page 1
Forum section: electronics / general

author: Jaunedeau
author_rank: Regular Contributor
timestamp: December 03, 2018, 10:44:22 am
content: Hi,I did a few AVR programs in assembly it worked well. Now I try with C. I use atmel studio 7, things worked fine using avr/io.h, but now I try to use ASF and the led won't blink. In this code, the short blink occurs, the longer one does not (I can't switch on or off the led using ASF, setting the port direction does not work either) :Code:#include <asf.h>#include <avr/io.h>#include <util/delay.h>#define LED_0 IOPORT_CREATE_PIN(PORTC, 0)int main (void){board_init();ioport_init();PORTC = 0b1111111;// This does not work, I need to add the second line.ioport_set_pin_dir(LED_0, IOPORT_DIR_OUTPUT);DDRC = 0b1111111;while (1) {// this short blink occursPORTC &= 0b11111110;_delay_ms(1000);PORTC |= 0b00000001;_delay_ms(1000);// this longer one does notioport_set_pin_level(LED_0, IOPORT_PIN_LEVEL_LOW);_delay_ms(8000);ioport_set_pin_level(LED_0, IOPORT_PIN_LEVEL_HIGH);_delay_ms(1000);}}What I did :- File -> new -> Project... -> GCC C Executabl // Could not use "Atmel Start Project" because it apparently does not support Atmega8- ASF -> Board Wizard -> User Board template - megaAVR- ASF -> ASF Wizard -> Added IOPORT - Output Port Controler (driver) // Generic board support (driver) was already added- Typed the code that I posted in this message in the src/main.c file that has been created- Deleted the main.c file that has hade been generated at first stepIs there a step I missed ?Thank you,Jaune.There are two warnings when I build :Code:------ Build started: Project: Blink3, Configuration: Release AVR ------Build started.Project "Blink3.cproj" (default targets):Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').Target "CoreBuild" in file "D:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "c:\users\fabien\Documents\Atmel Studio\7.0\Blink3\Blink3\Blink3.cproj" (target "Build" depends on it):Task "RunCompilerTask"Shell Utils Path D:\Program Files (x86)\Atmel\Studio\7.0\shellUtilsD:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 8 --output-syncBuilding file: ../src/main.cInvoking: AVR/GNU C Compiler : 5.4.0In file included from ../src/ASF/common/services/ioport/ioport.h:126:0,from ../src/asf.h:62,from ../src/main.c:1:../src/ASF/common/services/ioport/mega/ioport.h: In function 'arch_ioport_set_pin_sense_mode':c:\users\fabien\Documents\Atmel Studio\7.0\Blink3\Blink3\src\ASF\common\services\ioport\mega\ioport.h(378,12): warning: unused variable 'port_id' [-Wunused-variable]port_id_t port_id = arch_ioport_pin_to_port_id(pin);^In file included from ../src/main.c:4:0:d:\program files (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\util\delay.h: At top level:d:\program files (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\util\delay.h(92,3): warning: #warning "F_CPU not defined for <util/delay.h>" [-Wcpp]# warning "F_CPU not defined for <util/delay.h>"^

author: Jaunedeau
author_rank: Regular Contributor
timestamp: December 03, 2018, 12:38:44 pm
content: I changed the MCU to m328p in atmel, and flashed the firmware on an arduino pro mini : it works.could it be that the support for atmega8 in ASF is very basic ?

author: HB9EVI
author_rank: Frequent Contributor
timestamp: December 03, 2018, 12:53:16 pm
content: Didn't spend much time with ASF, but what I've seen, I didn't really like so much. Like all those libraries with adstractions of the hardware, it just bloats the code you're producingSince you obviously know to do the things the classical way, my advice'd be to do it that way only and use the ASF maximally as a reference code source to implement fancier hardware.

author: mvs
author_rank: Frequent Contributor
timestamp: December 03, 2018, 01:05:04 pm
content: Quote from: Jaunedeau on December 03, 2018, 12:38:44 pmOld ATmega MCUs have different register address numbering scheme. A brief look at "common/services/ioport/mega/ioport.h" shows that atmel have not implemented it.You may add it by yourself.

author: Raj
author_rank: Frequent Contributor
timestamp: December 08, 2018, 04:42:44 pm
content: mega8 is a different product line from mega88,168,328eg,mega8 doesn't have built in thermometer,can't be run on 20mhz etc,etc