24 votes
Accepted

Why does compiler optimization flag cause function definitions other than main() to break program in AVR ATMega C code?

These are not bugs that you are encountering. The problem goes deeper than just compiler optimization flags. It is a pure coincidence it happens to work at all. The code isn't compiled properly ...
Justme's user avatar
  • 149k
23 votes
Accepted

Avr-gcc using repeated addition instead of MULU instructions

Assuming that you want to optimize for speed: Unless you really find out how many cycles it takes if you use mul, you can't compare. So let’s try: If you use the <...
Curd's user avatar
  • 16.3k
18 votes
Accepted

Why doesn't the compiler use directly LSR

According to C language specification any value whose size is less than the size of int (depends on the particular compiler; in your case ...
Curd's user avatar
  • 16.3k
15 votes

Compress .hex file for micro-controller

You can not compress the hex code, you can only try to reduce it. Try different? compiler settings (maximum optimization and optimize for size) Pick your way through the source code and see what can ...
Oldfart's user avatar
  • 14.4k
13 votes

Why does compiler optimization flag cause function definitions other than main() to break program in AVR ATMega C code?

You know that something goes really wrong when at address 0 there is no vector table, which would be an array of RJMPs or ...
emacs drives me nuts's user avatar
11 votes

Compress .hex file for micro-controller

The MCU cannot execute compressed code. However, there are some things you can do: Instead of using full fledged library functions, create some or all of the functions yourself; this way you can ...
Michel Keijzers's user avatar
11 votes

Why does compiler optimization flag cause function definitions other than main() to break program in AVR ATMega C code?

Thank you for providing the dump output! You've captured the smoking gun: See ATmega8515 Datasheet | Microchip page 54: The first instruction must be rjmp .init (...
Tim Williams's user avatar
  • 34.1k
10 votes

Convert the type of calculation result in if() to uint8_t

rxWritePos is already uint8_t so obviously the cast (uint8_t)rxWritePos is nonsense - you ...
Lundin's user avatar
  • 20.2k
9 votes
Accepted

Convert the type of calculation result in if() to uint8_t

You need parentheses around the whole expression: (uint8_t)(rxWritePos-1). If rxWritePos = 0: ...
DamienD's user avatar
  • 3,305
8 votes

Compress .hex file for micro-controller

In addition to the excellent suggestions provided in the other answers here I want to comment that there can be a huge difference in how much compilers (and linkers) can optimize code. I worked at a ...
Michael Karas's user avatar
8 votes

Compress .hex file for micro-controller

The first step for any kind of optimisation is find out what's doing it. Your first move should be to get the linker to dump the address of every identifier in the build. That's all functions and all ...
Graham's user avatar
  • 6,150
7 votes

Avr-gcc does not compile correctly without optimizations, but works (badly) with -Os

You'll need to inspect the output of avr-objdump to see what exact instructions were generated for your code. Incidentally, it would be helpful to include your C ...
Dmitry Grigoryev's user avatar
7 votes
Accepted

avr-gcc keypad interfacing code problem

In an abstract manner the code does this: ...
the busybee's user avatar
  • 3,034
6 votes

avr-gcc keypad interfacing code problem

Here is your code with the comments that it should have had all along added in, plus tables showing exactly what the shift operations are doing (the latter shouldn't be necessary for any experienced C ...
Dave Tweed's user avatar
  • 173k
6 votes

Compress .hex file for micro-controller

There is no "practical" way to run compressed code on an AVR so your problem becomes "how do I optimize the size of my firmware". Toolchain tricks (ie. you don't have to modify your code): What is ...
filo's user avatar
  • 8,951
5 votes
Accepted

ISR, volatile and ATOMIC_BLOCK

Non-AVR-specific answer: Jumping into an ISR from a normal execution thread generally requires a context switch, where the current state of the CPU is saved somewhere (stack, shadow registers) so ...
Adam Lawrence's user avatar
5 votes
Accepted

UART with PC : Reciving absurd characters in PC

Your baud rate divisor seems to select a baud rate of 19200 instead of 9600: baud = (clock speed) / ( 16 * (UBRR + 1) ) Try to set ...
Dmitry Grigoryev's user avatar
5 votes

i'm using atmega32 to do an automatic railway gate project i wrote the code ,but i have a problem with it that it doesn't give me the required output?

when i burn it on the kit it doesn't work . what is the wrong with this code ?? Who knows? Could be anything. You haven't told us how you know it doesn't work. But that is not relevant, I will tell ...
pipe's user avatar
  • 14.3k
5 votes

Push button counting

You need to be aware that as written your code will spin around the while loop dozens if not 100's of times seeing the one or the other of the switches pressed. Since your IF statement only checks for ...
Michael Karas's user avatar
5 votes
Accepted

Atmega328p ADC - value keeps returning zero when connected

The DS18x20 series are digital thermometers using the One-Wire protocol on their data pin. Look up any of the Dallas/Maxim DS18b20 libraries to use this one. If, on the other had, you want an analog ...
JRobert's user avatar
  • 3,192
5 votes

Can I use C++ stl in avr-gcc?

It is very well possible to use C++ on the AVR. Arduino has been doing it for ages. Unfortunately, avr-g++ does not ship with a C++ standard library (the successor to the old STL), so you have to rely ...
Erlkoenig's user avatar
  • 226
4 votes

avr-gcc float macro error

I got it! As Dave Tweed suggested in a comment, the issue was not the declaration itself but the way I was using that macro. In other lines I was doing this: ...
Virgil Litan's user avatar
4 votes

What is STM8 hardware and software interrupt latency?

The STM8 takes 9 clock cycles to go to the ISR. And takes 9 clock cycles to return. Reference: STM8 programming manual (Doc No. PM0044) pg. 14.
Bharath's user avatar
  • 41
4 votes
Accepted

Difference and compatibility between AVR xxxA and xxx/xxxV series

The ATtiny13 is the original version and uses a different process technology than the ATtiny13A. The A-suffixed parts are fabricated with a low power process marketed as "picoPower", and the main ...
jms's user avatar
  • 8,641
4 votes
Accepted

Unexpected bits when shifting out (ATtiny85)

You're reading your binary constants backwards when calculating your expected 'Correct' bits. Your code which reads the individual bits: ...
brhans's user avatar
  • 14.7k
4 votes
Accepted

AVR SPI slave first byte problem

The answer is in your question already. Simultaneously being the key word. Interrupt is called on RX complete, which is when the a byte from master has already been received. This must then also mean ...
domen's user avatar
  • 250
4 votes
Accepted

AVR atmega328p - Can I use port C as digital output pins?

can I use port A as digital output pins without ruining the microcontroller? Yes you can. Below table describes about Sink and source capabilities: VOH is when you try to output a high signal. ...
User323693's user avatar
  • 9,311
4 votes

Compress .hex file for micro-controller

If you are looking for ways to reduce the size of your program code - besides having the optimizing compiler & linker chopping away some, and not using standard library functions, as others have ...
sktpin's user avatar
  • 171

Only top scored, non community-wiki answers of a minimum length are eligible