error: __builtin_avr_delay_cycles expects a compile time integer constant

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

Hi all. Total noob here, please go easy on me. I've been using arduino for a while and I want to start coding AVR without arduino.

 

I tried to write a simple LED blinking program which makes use of _delay_ms() but I get this error.

 

/usr/avr/include/util/delay.h:187:2: error: __builtin_avr_delay_cycles expects a compile time integer constant
  __builtin_avr_delay_cycles(__ticks_dc);

 

I have googled this a lot and found several threads here, on stackexchange etc about it, but all of them were trying to pass a variable to _delay_ms() and the answers given was always to pass a constant to _delay_ms(). However I am already passing constants to it and it still won't compile.

 

#define F_CPU 1000000UL
#define __AVR_ATmega324PA__
#define __OPTIMIZE__

#include <avr/io.h>
#include <util/delay.h>

int main (void){
  DDRC |= (1 << 0);     //Set PINC0 to output

  for(;;){
    PORTC |= (1 << 0);  //set C0 HIGH
    _delay_ms(500);
    PORTC &= ~(1 << 0); //set C0 LOW
    _delay_ms(500);
  }
}

The

#define __OPTIMIZE__

line is because without that I get a compiler warning that the delay won't work as expected (but it at least it does compile).

 

 

I'm on linux so I am not using an IDE, just compiling on the command line with avr-gcc.

avr-gcc version 7.2.0-1

I have arduino-avr-core version 1.6.19-1, I assume those are the core files it is using.

 

Please point out where I'm going wrong.

 

Many thanks.

Last Edited: Sun. Oct 29, 2017 - 09:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define __AVR_ATmega324PA__

KX36 wrote:
just compiling on the command line with avr-gcc.
So you don't use a -mmcu option, do you?

What happens when you remove that #define (and the #define __OPZIMIZE__) and instead do it the right way, by using -mmcu=atmega324pa and -Os?

Stefan Ernst

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

Yeah, that works. Thanks buddy.