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

How to find the UART line is free for send data

Welcome to the biggest challenge with half-duplex communications systems. RS-485 is not a protocol, it's a standard which defines the electrical properties for a half-duplex(*) differential link. ...
Tom Carpenter's user avatar
23 votes
Accepted

What's the maximum time an interrupt service routine can take to execute on ATmega328P?

If nothing else is running in the MCU, then you are free to take as long as you like in the ISR. But, this is a bad habit to get into, and it means that if you want to do anything else, you'll likely ...
Neil_UK's user avatar
  • 166k
22 votes

Is it ok to set the unused I/O pins of the ATmega8A to input and connect all of them to ground

The ATMega8A Datasheet p.61 states: 13.2.4 Unconnected pins If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of the digital inputs are ...
Math Keeps Me Busy's user avatar
16 votes
Accepted

What is this schematic symbol with intersecting triangles?

It's a MOS pass/transmission gate.
DKNguyen's user avatar
  • 56.7k
15 votes
Accepted

Unexpected behaviour with pow(2,x) in Embedded C

While this is a programming question, it is one that can turn up quite often in embedded settings, so it's not really off-topic here. The most likely issue is indeed caused by truncation (not ...
Chris Stratton's user avatar
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
14 votes
Accepted

TQFP and VQFN on same footprint: good idea or bad?

Has anyone tried this successfully? My company does this in current designs because of Chip shortages and not just with this part. There are many companies that are doing this more and more. Or some ...
Voltage Spike's user avatar
  • 82.4k
14 votes
Accepted

AVR code disassembly - what is this code doing?

I added some comments to explain the function. ...
Jens's user avatar
  • 6,919
13 votes
Accepted

Atmega naming scheme (324p vs 328p)

The numbers of Atmega devices follow a quite simple basic scheme. Let's take the Atmega644PA-AU as an example. "64" The first digits always mark the size of the Flash in Kibibyte This is ...
asdfex's user avatar
  • 2,729
13 votes
Accepted

ATmega 2560 is getting hot controlling MOSFETs

You have improper circuit design having the MCU pin drive directly into the NPN transistor base. You need a resistor in series with the NPN base to limit the amount of current flow. As designed you ...
Michael Karas's user avatar
13 votes
Accepted

Is it ok to set the unused I/O pins of the ATmega8A to input and connect all of them to ground

Your solution will work. There are other options too, as wiring them directly to ground will prevent the use of those pins easily in case you need more pins for temporary testing and debugging. ...
Justme's user avatar
  • 149k
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
12 votes
Accepted

Serial communication baud rate issue

This means at each edge we are receiving and data can be lost since edges are not that accurate. A UART (as I believe you are talking about) makes use of start and stop bits to acquire ...
Andy aka's user avatar
  • 457k
11 votes

Reading a huge number of analog sensors in real time

The obvious answer is muxing, this means that you make electric path's dynamically. So just iterate through the whole matrix, one at a time, or as many ADC (Analog to Digital Converter) inputs as you ...
Harry Svensson's user avatar
11 votes

What's the maximum time an interrupt service routine can take to execute on ATmega328P?

In the worst case, an ISR can run until the next interrupt of the same type occurs again. But in general, it's poor design practice to spend more time in an ISR than absolutely necessary, because it ...
Dave Tweed's user avatar
  • 173k
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
Accepted

High-temperature microcontroller

A web search using the terms high temperature microcontrollers turns up a number of candidate manufacturers. While individual products on this list may become obsolete with time, some manufacturers ...
Russell McMahon's user avatar
  • 150k
11 votes
Accepted

ATmega8515 - odd results when auto-detecting external SRAM

There are two possibilities I can think of as to why the lines will be repeatably holding their value when accessing the non-existent RAM. You have the bus keeper functionality enabled on the data ...
Tom Carpenter'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
Accepted

ATmega - Why is the prescaler factory defaulted to 8?

Note the dependency of the maximum allowed clock speed on the supply voltage: E.g. the 644PV can only reach 4 MHz when running at 1.8V (similar for other chips) If the controllers were programmed to ...
asdfex's user avatar
  • 2,729
10 votes
Accepted

Microcontroller sending garbage to Raspberry

Your issue is that you are calculating the baud rate divisor for "double speed mode" but you are neglecting to enable that mode by setting bit 1 of UCRS0A, which defaults to 0. This means that the ...
Chris Stratton's user avatar
10 votes
Accepted

Why does my atmega32's malloc function returning me the pointer address in multiple of 4?

For the first question: There is 2kB of SRAM. There is an additional 32bytes of CPU registers, and a further 64bytes of I/O registers (things like the PORTA/DDRA/etc. registers). Add these all up ...
Tom Carpenter's user avatar
10 votes

Increase memory of an ATmega32

Global variables/types Changing the type of global variables (e.g. use uint8_t or a similar 1 byte instead of long), or use bits to store boolean arrays. Remove static variables and replace them by ...
Michel Keijzers's user avatar
10 votes
Accepted

Does the counter of an Atmega328 still count inside interrupt handler?

The counter continues counting unless you set the necessary control bits to stop it. The interrupt handler won't stop it.
David Molony's user avatar
  • 1,179
9 votes

Is ESP8266 an AVR?

ESP family isn't a AVR! The Library you refere to is a Arduino IDE (Integrated Development Environment) library. The Arduino IDE has a hardware layer that gives it the ability to utilize several ...
MatsK's user avatar
  • 748
9 votes
Accepted

Weird bit stretching on ATmega2560 uart

The problem is caused by the 'ADC Noise Reduction Mode'. I enter this mode to do ADC conversions: If the ADC is enabled, a conversion starts automatically when this mode is entered. In this mode, some ...
NZD's user avatar
  • 345

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