Skip to main content
26 votes

Are high speed crystals better at something compared to 32768 Hz crystals?

STM32L4 cannot directly use the LSE as a PLL source. The reason for this is also the reason why you'd prefer a higher frequency crystal: phase noise. The 32768 Hz crystal oscillator generates a sine ...
jpa's user avatar
  • 9,021
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
  • 164k
24 votes

Are high speed crystals better at something compared to 32768 Hz crystals?

You simply cannot derive any arbitrary clock from 32768 Hz. Your PLLs can typically only do integer multiples, and with the dividers in typical MCU clock trees, you could do but a very limited set of ...
Marcus Müller's user avatar
24 votes
Accepted

Tie all unused GPIO to GND?

The PIC24FJ64GA004 Datasheet specifies the general practice for unused I/Os: 2.8 Unused I/Os Unused I/O pins should be configured as outputs and driven to a logic low state. Alternatively, connect a ...
Velvet's user avatar
  • 4,550
17 votes

Tie all unused GPIO to GND?

Apart from the valid reasons given in answers, if you are developing a circuit board, it's always useful to have spare IO brought out to a small but convenient test point just in case you suddenly ...
Andy aka's user avatar
  • 467k
17 votes

How can a microcontroller (such as an Arduino Uno) that requires 7-21V input voltage be powered via USB-B which can only run 5V?

An arduino uno is not a microcontroller; it's a dev board that has a microcontroller on it, along with a bunch of supporting components. One of those supporting components is a device called a voltage ...
Hearth's user avatar
  • 36.4k
14 votes

Is it a good idea to perform I2C Communication in the ISR?

In the olden days, when we had a single thread of execution, and many sources of interrupts, you kept the ISR as short and quick as possible, so that it is able to keep up with many frequent interrupt ...
Simon Fitch's user avatar
  • 42.2k
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
13 votes

Can I control any transistor (NPN/PNP) using a GPIO pin of my MCU? Is my schematic correct?

To "is my schematic correct"... The below circuit is wrong. First, Q1 will try short out the rail when PB5 is driven HIGH. Second, Q1's base is a diode to GND so Q1 will try to clamp PB5 to ...
TonyM's user avatar
  • 23.7k
12 votes

Are high speed crystals better at something compared to 32768 Hz crystals?

If you require to do some things related to frequency or time done with better than the datasheet mentioned 0.25% precision for LSE trimmed operation at the system clock frequency, then you can't use ...
Justme's user avatar
  • 164k
12 votes
Accepted

RTC super capacitor is discharging very fast

This explains the issue. When 5V_uC is off the RTC will be working from supercapacitor and the microcontroller is also off at that time.The clock output of the RTC will be in enabled state. You can'...
Justme's user avatar
  • 164k
12 votes
Accepted

What happens if a microcontroller stays in reset?

A couple of issues: A MCU usually has a default reset setting where all GPIO are set as inputs. This is an advantage in terms of current consumption, but it is a disadvantage in terms of ruggedness ...
Lundin's user avatar
  • 21.6k
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
Accepted

What happens if an MCU boosts its own supply voltage while running?

I've done that with an ATtiny84 with no problems. When in sleep mode parts of the circuit (such as the analog section) are powered down and the supply voltage is dropped from 5V to 1.8V with only the ...
Kevin White's user avatar
  • 33.8k
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
  • 43.4k
11 votes

STM32 for loop slows down code too much

Speaking about performance without mentioning how you compile the code is kind of pointless. It shouldn't be a mind-blowing realization that optimized code runs faster than code with optimization ...
Lundin's user avatar
  • 21.6k
11 votes

Is it a good idea to perform I2C Communication in the ISR?

I don't believe it's a good idea, in general. The I2C protocol allows for clock stretching, which means that any I2C device you're trying to talk to can effectively stop your bus, or at least dork ...
Scott Seidman's user avatar
10 votes

Low consumption resistor pair

May I offer a different approach? Instead of turning off the voltage divider, reduce its current drastically and buffer the voltage. simulate this circuit – Schematic created using CircuitLab
Davide Andrea's user avatar
10 votes

Tie all unused GPIO to GND?

It might be relevant, but it depends. And you already talk about two scenarios, you mention tying unused IO pins to ground (without mentioning any resistors so reader may assume direct connection), ...
Justme's user avatar
  • 164k
10 votes

How do input pins work?

Setting pull-up or pull-down switches an internal resistor (or something similar) between the input pin and either Vdd or GND. So you effectively have either of these: simulate this circuit – ...
Spehro 'speff' Pefhany's user avatar
9 votes
Accepted

How are different GPIO frequency modes implemented?

Mostly, the slew rate for GPIOs is increased by adding more drivers in parallel like the one shown below. I have shown above an image of a GPIO that has 2 drivers. Each has an independent enable as ...
sai's user avatar
  • 4,172
9 votes

What is the function of the comparator in the ATMEGA328p ADC block diagram?

The shown ADC converter works by stepwise control of the 10-bit DAC, comparing the result with the analog input signal from the mux. It does this via a "binary chop" / "successive ...
colintd's user avatar
  • 7,906
9 votes

What happens if a microcontroller stays in reset?

If you hold the MCU in the reset state, it will do nothing, but that's not necessarily what you want. Power-wise, consumption will probably be higher than in the low power sleep states. And of course ...
bobflux's user avatar
  • 80.3k
9 votes

Help in identifying an abnormal PCB found suspiciously

As surmised in the comments already, this is most likely a cheap "mood light" USB device, which has two RGB LEDs for increased brightness, and a button to change the mode / color... If you ...
Attie's user avatar
  • 2,438
8 votes
Accepted

How to prevent photoresistor sensor from draining battery

Sleep on the watchdog timer (or other low power timer) instead and then only power the photodetector at the end of each sleep. Connect the top of the photoresistor circuit to a GPIO so that you can ...
Jasen  Слава Україні's user avatar
8 votes
Accepted

What is expected resistance of MCU power supply pins?

I am hesitant to apply external voltage to it As long as it is current-limited, it should be OK. Visual inspection does not show any bridges, but it is hard to tell with LQFP pitch. You need a good ...
Kuba hasn't forgotten Monica's user avatar
8 votes

Advice on making a quad-directional power/data connector

Instead of four discrete pins, use a 4-circuit circularly-symmetrical connector. These connectors may be plugged-in in any orientation. Regardless of orientation, each contact is connected to the ...
Davide Andrea's user avatar
7 votes

Absolute Maximum ratings of a device

Your assumptions are mostly correct. Many chips have ESD protection diodes from the pins to VCC, and it is the power dissipation of the current flowing through them that would damage them. The limit ...
CL.'s user avatar
  • 19.7k
7 votes

Are high speed crystals better at something compared to 32768 Hz crystals?

Consider a STM32L412K8U6TR. The only direct use the 32.768kHz crystal has is for the RTC (it can optionally be fed to a GPIO as well). The watchdog is clocked off the internal low frequency RC ...
Spehro 'speff' Pefhany's user avatar
7 votes
Accepted

Can I control any transistor (NPN/PNP) using a GPIO pin of my MCU? Is my schematic correct?

No, you can't control any transistor, because there are different kinds of transistors, some may require more current or more voltage than any microcontroller can provide. Your schematic has no base ...
Justme's user avatar
  • 164k

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