58
votes
Accepted
Why do we need a bootloader separate from our application program in microcontrollers?
A bootloader on a microcontroller is responsible for updating the main firmware over a communication channel other than the programming header. This is useful for updating firmware in the field over ...
55
votes
MCU programming - C++ O2 optimization breaks while loop
The code optimizer has analyzed the code and from what it can see the value of choice will never change. And since it will never change, there's no point in ...
54
votes
Accepted
Why do microcontrollers need a programmer device?
That's what the programmer does.
It takes the binary output from the compiler and stores it in the MCU's Flash EPROM, usually over a serial bus.
Flash EPROM requires a programming algorithm to store ...
43
votes
Accepted
Create Circuit Simulation
I wrote the simulation engine that powers CircuitLab from scratch: from the sparse matrix library up through component models and simulation modes. My co-founder wrote the front-end. It ended up being ...
35
votes
Accepted
Why is a register initialised through bitwise operations instead of a binary string?
0b00001000 vs 1<<3
The binary notation is not standards-compliant C. That might just rule it out.
If it doesn't rule it ...
32
votes
Why do microcontrollers need a programmer device?
A programmer is the implementation of " via specific bus,".
Some devices have inbuilt bootloaders (may be hardware or software or firmware) that allow the use of a port of some sort to load ...
31
votes
Is it possible to draw circuits through code?
If you are familiar with \$\LaTeX\$, you can use circuitikz to draw nice circuits by writing code.
Example.
More Examples
27
votes
Why do we need a bootloader separate from our application program in microcontrollers?
So that the loading process can recover from errors.
Suppose there is a communication error or power disconnects during an upgrade. If the boot loader were part of the application you were upgrading ...
22
votes
How can I estimate the speed of this code section for this microcontroller?
Since the code snippet you're interested in isn't big, you could disassemble your compiled code, look at all the assembly instructions and count how many cycles they need. You can find the number of ...
21
votes
Why do microcontrollers need a programmer device?
transfer it to specific place in flash memory via specific bus
This is exactly what flash programmer devices do. They just don't use something slow and archaic like RS232, but instead nowadays ...
19
votes
Accepted
What does a function mean that doesn't have "void", "int", etc in front of it mean?
The functions are interrupt handlers, defined using the ISR(vector, attributes) macro. The macro generates a proper platform-specific function signature, including ...
18
votes
Accepted
Do you typically need to program-in a USB communication protocol?
Like any protocol stack, USB incorporates components representing various layers. High-level drivers and libraries provide higher-layer functionality on top of lower layers, effectively abstracting ...
17
votes
Accepted
How does one go about learning to program a new micro controller?
Generally speaking you won't find all the information in a single document on newer 32-bit MCUs. The "data sheet" is more like a light overview of capabilities with electrical ...
17
votes
What's a good way to assert in embedded microcontroller code?
It depends.
On an ARM platform there are very low level error handlers which indicate that some kind of low level problem has occurred (e.g. illegal memory access) and these need to have specific ...
16
votes
Is it possible to draw circuits through code?
Check out SKiDL (https://github.com/xesscorp/skidl), this is along the lines you're thinking.
Edit (as req'd): SKiDL allows procedural description of all circuits (rather than just digital), instead ...
16
votes
Is it possible to drive a 2 X 16 LCD display using logic gates? (Without computer)
It is possible to make a circuit out of logic gates that would be able to initialize and display characters onto a 16x2 LCD character mode module. It is also possible to make a circuit out of logic ...
16
votes
Accepted
What's a good way to assert in embedded microcontroller code?
The assert function as such is problematic, as you've probably noticed since you asked this question. No, using it is not good practice. Do not mix up "lots of ...
15
votes
Accepted
MCU programming - C++ O2 optimization breaks while loop
(Cross site duplicate on SO about the thread case, rather than interrupt/signal-handler case). Also related: When to use volatile with multi threading?
A data race on a non-...
15
votes
How does one go about learning to program a new micro controller?
ST Microelectronics separates things into Datasheets and User Reference Manuals. The datasheet has part specific information while the reference manual has the information common between parts of a ...
14
votes
Is it possible to draw circuits through code?
Many programs can draw a schematic. None that I know of can draw a good schematic: One that emphasizes the most important information, and arranges the circuit in a clear and easy to understand way.
...
14
votes
How can I estimate the speed of this code section for this microcontroller?
Let's do it!
Say we have the code
...
13
votes
PIC12F675 GP4 doesn't work
You have configured the PIC to output the internal clock signal on GP4 using
#pragma config FOSC = INTRCCLK
Replace INTRCCLK with INTRCIO.
13
votes
Why is a register initialised through bitwise operations instead of a binary string?
Well, the example is very poor, as for initializating the whole port after reset, either one can be used.
The point is that later on, you might want to control one bit only, and keep the state of the ...
12
votes
FPGA - DIY Programming
Yes, it would work just fine.
Actually, the development tools for most FPGAs allow you to program the external flash directly through the FPGA's own JTAG connection, eliminating the need for a ...
12
votes
Accepted
PIC12F675 GP4 doesn't work
Just to add to Spehro's correct answer:
Since the microcontroller you are using has only 8 pins, they necessarily must share functionality to provide the various features that the device is capable ...
12
votes
Use of VCC and GND pins on programming headers
Well, you certainly must connect the GND pin so that the programmer and the mcu share a common ground.
The 3V3 pin is not necessarily there to power the MCU. Some programmers (eg. Segger's J-Link) ...
11
votes
Why do we need a bootloader separate from our application program in microcontrollers?
They're generally there to allow you to update your main application program.
You need some code which knows how to erase and reprogram some of the internal flash, that can't be the main program as ...
11
votes
How can I estimate the speed of this code section for this microcontroller?
I normally use the built-in simulator of Atmel Studio which has a cycle counter in the processor status window.
This is a combined screenshot from stepping though the code:
]
As you can see, the ...
10
votes
How to make a PCB based on ATtiny easily updatable by end users?
Take a look a the micronucleus bootloader...
https://github.com/micronucleus/micronucleus
It allows an ATTINY to accept a code download over a (slightly hackey) USB connection. It is widely used and ...
10
votes
How can I flash a castellated ESP32?
You need to connect it as shown in Fig 4 of your datasheet, at least to power, reset and serial. A usb-serial chip as in the development kit (soldered, not socketed, module) would allow programming ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
programming × 828microcontroller × 276
pic × 105
arduino × 90
c × 83
embedded × 77
stm32 × 75
avr × 58
microchip × 37
flash × 35
arm × 33
microprocessor × 30
spi × 27
fpga × 26
atmega × 26
programmer × 26
usb × 25
atmel × 23
jtag × 22
attiny × 19
bootloader × 18
assembly × 17
c++ × 17
interrupts × 16
pcb × 15