why do we need to initialize device

Thread Starter

mukesh1

Joined Mar 22, 2020
68
Hi guys

I see whenever we start to write program we always initialize device (MCU, LCD, SENSOR, etc). Why do we need to initialize device first What are disadvantage if we do not initialize device
 

ronsimpson

Joined Oct 7, 2019
4,691
Many devices, at power up, are in low power shut down mode. You must send a command to turn them on.
Many devices, at power up, are in default mode. Temperature sensor might be in "C" mode but you want it in "F" mode.
A MCU might have random data in RAM at power up and it should be reset to "0".
Some devices do a self test at power up. After that they can function.
It is very common for a device to have more than one function. It can only do one function at a time.
In micro computers it is common for each pin to have more than one function.
….Pin10 can be a output for a serial port, Analog input, Digital input, Digital output, (you must choose which)
….A UART (serial port) needs to be enabled, the speed set (9600) the number of data bits set (7/8), number of stop bits set (1/2), parity turned on/off etc.
 
Last edited:

ci139

Joined Jul 11, 2016
1,989
it applies for the analog and mixed circuits as well
with mosfet switching circuits you don't want the startup... (when the supply voltage has not reached it's level yet + when the capacitors have not charged to their "operating points" + the control currents and voltages have not at the levels they would function properly/predictably) ...to be undefined . . . especially with the complex circuits

is one of the uses of the 555 timer and it's modern variants . . . to generate the startup sequencing delays

also , to few levels higher . . . with the simple computer program - you first define and initialize the compiler options... (such as weather the FP divide by zero or overflow will create an OS level evt. or can be hooked to a "local/user/programmed" handle) , ...constants and essential data structures to be able to have something to work with

. . . -- it's essential
 

MrChips

Joined Oct 2, 2009
34,809
If you ever have to program an ARM processor you will encounter why you have to initialize the device.
All modules are in power-down mode. Even the system oscillator is in power down mode. The MCU starts up in skeleton mode, i.e. bare bones.
 

BobaMosfet

Joined Jul 1, 2009
2,211
Hi guys

I see whenever we start to write program we always initialize device (MCU, LCD, SENSOR, etc). Why do we need to initialize device first What are disadvantage if we do not initialize device
Think. It's a bit obvious. So we know what state things are in. Otherwise they are in a random, unstable state which will cause unexpected, unplanned for operation. Part of designing things is to design a box within which logic operates so you can handle the finite cases within that box. If you start in an uninitialized state, that device might operate outside the box of design parameters your logic works within- and thus function in correctly.
 

MrChips

Joined Oct 2, 2009
34,809
More importantly, the system has different operating modes and options to choose. It is wonderful that the designer of the hardware anticipated this and allowed the user to choose from different options.

You need to choose your option and that is the purpose of initialization.
 
Top