AVR-GCC is part of the GNU Compiler Collection (GCC) collection of open source compilers that targets the popular AVR microntroller produced by Atmel. It supports both the C and C++ languages.
Questions tagged [avr-gcc]
120 questions
14
votes
2 answers
Avr-gcc using repeated addition instead of MULU instructions
I recently compiled some C++ code for the ATmega1284P in Atmel Studio and was analyzing the timings of some routines using my scope. To my surprise, a loop I thought I had optimized was taking longer than expected.
After taking a peek at the…

Hackstaar
- 886
- 6
- 22
10
votes
1 answer
Why doesn't the compiler use directly LSR
Hi I've been working on a project using an Arduino Uno (so ATmega328p) where timing is quite important and so I wanted to see into which instructions the compiler was converting my code. And in there I have a uint8_t which I shift one bit to the…

xZise
- 239
- 1
- 7
9
votes
4 answers
Why GCC compiler omitting some code?
I can not understand why GCC compiler cutting out part of my code while it preserve absolutely the same one in the neighborhood?
The C code:
#define setb_SYNCO do{(PORTA|= (1<<0));} while(0);
ISR(INT0_vect){
unsigned char i;
i = 10;
…

Roman Matveev
- 2,942
- 7
- 32
- 75
8
votes
2 answers
Macros V/S inline functions while programming for avr-gcc
I have been doing my first serious work of programming these days. I have been exposed to a lot of code by different developers. One thing I find confusing is how do these developers decide when to use a macro definition and when to use a inline…

Rick_2047
- 3,897
- 5
- 46
- 68
8
votes
1 answer
How do I create a static library for the AVR Atmega328p?
I am attempting to create a library much like the Arduino in C.
I have tried in the past and although I have lost the code, I remember simply getting loads of undefined references to functions specified in the header files and in the library which…

Will03uk
- 203
- 3
- 5
7
votes
4 answers
'bit' type for AVR Microcontroller programming
I have written a code for 8051 microcontroller, where I used bit type, something like this:
static bit done_flag = 0; /* bit variable */
bit testfunc ( /* bit function */
bit flag1, /* bit arguments */
bit…

gpuguy
- 1,618
- 8
- 31
- 54
6
votes
1 answer
Programming an ATmega1284p with Arduino IDE and internal RC Oscillator?
I'd like to program an ATmega1284p with my AVR Dragon and the Arduino IDE. So far I have installed mighty1284p (http://maniacbug.wordpress.com/2011/11/27/arduino-on-atmega1284p-4/), after writing my (example) sketch I compile it using the Arduino…

Christian
- 621
- 12
- 22
6
votes
7 answers
Compress .hex file for micro-controller
I am currently writing a program in AVR Studio, here is the build *Memory Usage : *
Device: atmega32
Program: 9304 bytes (28.4% Full)
(.text + .data + .bootloader)
Data: 334 bytes (16.3% Full)
(.data + .bss + .noinit)
As…

Danial
- 223
- 2
- 6
6
votes
3 answers
Setting pin to high in function instead of main, not full voltage output?
I have a function which turns on a LED by setting PB1 to HIGH. The light from the LED is barely visible. If I set PB1 to HIGH in my main function the light from the LED is as bright as it should be.
It makes no sense to me since it's just changing…

rzetterberg
- 403
- 4
- 12
6
votes
2 answers
ISR, volatile and ATOMIC_BLOCK
From my experience so far I am aware of the following to pay attention to when working with ISRs:
An ISR should complete quickly
Variables shared between an ISR and the main execution path should be declared volatile to avoid accesses to it being…

Torsten Römer
- 487
- 2
- 7
- 18
5
votes
3 answers
Fastest moving averaging techniques with minimum footprint
I have tried few running averaging techs for smoothing the change in ADC data in AtMega48 for controlling lights(PWM) when rotating a pot(ADC).
The filters (pseudo codes):
Moving average:
adc_avg += new adc_raw;
adc_avg >>= 1;
8-point Moving…

Rick2047
- 739
- 8
- 13
5
votes
1 answer
Easiest way to get rid of __clz_tab in winavr compiled code?
I've ported a program from the arduino environment to a makefile build using winavr, which, in turn, is based on avr-gcc (just like arduino).
However, my program started crashing, and after some investigation I found I was running out of data memory…

Adam Davis
- 20,339
- 7
- 59
- 95
5
votes
1 answer
Overflow interrupt firing only once
I've run into an issue where, it appears, my interrupt only fires once, then simply refuses to fire again on my ATMega32U2. I have the following (stripped down) code:
void init(void) {
DDRB = 0xff;
PORTB = 0x00;
TCCR0A = (1 << WGM01);
…

Bojangles
- 996
- 12
- 18
5
votes
1 answer
How to store array of values in EEPROM of ATmega16 and then read it in sequence
I have this program in which I can store a single value in EEPROM. Can I store an array of values in EEPROM? How?
#include
#include
// macro for easier usage
#define read_eeprom_word(address)…

user3052614
- 77
- 1
- 1
- 7
4
votes
1 answer
AVR-GCC: Ports Undeclared when compiling
My Setup
I'm running Ubuntu 12.10, and I want to be able to use gcc and avrdude to compile and program my ATmega328.
I followed this Ladyada tutorial: Ladyada AVR Tutorial
Everything installed perfectly, no errors or warnings. I have not installed…

Nick Williams
- 1,815
- 3
- 17
- 29