Embedded

All Contents

Lean EmbeddedEmbedded Interface
8051
Arduino
ESP32
ESP8266
PIC MCU
Embedded Companies
Embedded Interface
Embedded Protocol
Embedded Sensor
Sitemap
Embedded Interface 7 Segment (Add Soon)
Embedded Interface ADC (Add Soon)
Embedded Interface Button (Add Soon)
Embedded Interface EEPROM (Add Soon)
Embedded Interface LCD (Add Soon)
Embedded Interface LCD HD44780 (Add Soon)
Embedded Interface LED
Embedded Interface MCP23017
Embedded Interface Motor (Add Soon)
Embedded Interface PCF8574 and PCF8574A
Embedded Interface RTC (Add Soon)
Embedded Interface Switch
Embedded Interface Touch Kypad
Embedded Interface RGB LED (Add Soon)
Embedded Protocol
Embedded Protocol GetStart
Embedded Protocol Bluetooth
Embedded Protocol COAP
Embedded Protocol CAN
Embedded Protocol FTP
Embedded Protocol HTTP
Embedded Protocol I2C
Embedded Protocol MQTT
Embedded Protocol One Wire (OW)
Embedded Protocol SPI
Embedded Protocol UART
Embedded Protocol WiFi
Embedded Protocol Zigbee
Sitemap
Embedded Protocol All Post

Microcontrollers

4004 Microprocessor 

STM8S003 MCU

STM8S003 Controller Pinout ( STM8S003 TSSOP2)

STM Programmer

 You can buy this USB programmer from eBay   The ST-LINK/V2 is an in-circuit debugger and programmer for the STM8 and STM32 microcontroller families. The
single wire interface module (SWIM) and JTAG/serial wire debugging (SWD) interfaces are used to communicate with any STM8 or STM32 microcontroller located on an application board. for more details about the ST-LINK V2 programmer click here. SWIM is Single-WireInterface Module, See SWIM protocol details.  

ST-LINK V2 Pinout

Example: Hello World

In the hello world example will see the  LED Blink Program in STM8S003 Controller. Usually the first program of everything (Controller) in electronics we start from blink example.

Required? Infinite loop in Embedded system

Yes โ€” in most embedded systems, an infinite loop is required at the end of main() or in the main task.

Why?

  1. No Operating System Exit
    • Unlike desktop programs, thereโ€™s usually no โ€œreturn to OSโ€ in bare-metal embedded systems.
    • If main() finishes, the CPU may jump to an undefined location and execute garbage instructions, causing unpredictable behavior.
  2. Continuous Operation
    • Embedded systems often run indefinitely (controllers, sensors, appliances).
    • The infinite loop keeps the device active, continuously handling tasks, checking inputs, and controlling outputs.
  3. Low-Power & Idle Handling
    • The loop can contain sleep or low-power mode instructions to save energy while waiting for interrupts.

Typical example:

int main(void) {
    init_peripherals();
    while (1) {         // Infinite loop
        process_tasks();
    }
}

Exception:
In embedded code is running under an RTOS, main() might just create tasks and let the scheduler run; in that case, the infinite loop may be inside the task, not main() itself.

Timers in Embedded system

In embedded systems, timers are hardware or software components used to measure time intervals, generate delays, or trigger events at precise intervals.


1. Types of Timers

  1. Hardware Timers
    • Built into the microcontroller.
    • More accurate and independent of CPU execution speed.
    • Can work even when the CPU is in low-power mode.
    • Examples: 8-bit timers, 16-bit timers, watchdog timers.
  2. Software Timers
    • Implemented in code using counters and delays.
    • Less accurate (depends on CPU and OS scheduling).
    • Useful when hardware timers are already occupied.

2. Timer Modes

  • One-shot mode โ†’ Runs once for the set duration, then stops.
  • Periodic mode โ†’ Repeats at a fixed interval.
  • Capture mode โ†’ Records the time when an event occurs.
  • Compare mode โ†’ Generates an interrupt when the counter matches a set value.
  • PWM mode โ†’ Produces Pulse Width Modulated signals.

3. Common Uses

  • Generating delays without blocking the CPU.
  • Measuring time intervals (e.g., speed calculation in sensors).
  • Creating precise clock signals.
  • Scheduling tasks in real-time systems.
  • Driving PWM for motor control or dimming LEDs.
  • Timeout detection (e.g., watchdog timer to reset system on hang).

4. Example (C – AVR/ARM)

// Example: Configure Timer0 for 1ms interrupt
void Timer0_Init(void) {
    TCCR0A = (1 << WGM01);   // CTC mode
    OCR0A  = 249;            // Compare value for 1ms at 16MHz with prescaler 64
    TIMSK0 = (1 << OCIE0A);  // Enable compare match interrupt
    TCCR0B = (1 << CS01) | (1 << CS00); // Start timer with prescaler 64
}

ISR(TIMER0_COMPA_vect) {
    // This code runs every 1ms
}

Key point: In embedded systems, timers are essential for real-time control because they allow precise event scheduling without wasting CPU cycles.

Watchdog timer

A Watchdog Timer (WDT) in embedded systems is a hardware or software timer used to detect and recover from malfunctions.

Purpose

The WDT ensures that if your program gets stuck (e.g., infinite loop, deadlock, or crash), the system can reset itself automatically to resume normal operation.


How it works

  1. Enable the WDT in your microcontroller.
  2. The WDT counts down from a preset value.
  3. Your code must periodically โ€œkickโ€ or โ€œfeedโ€ the WDT before it times out.
  4. If the WDT is not fed in time, it assumes the system is stuck and resets the MCU.

Example scenario

  • In normal operation:
    The main loop updates sensors, processes data, and calls feed_watchdog().
  • If a bug causes the loop to hang:
    The watchdog is not fed โ†’ WDT expires โ†’ MCU resets โ†’ System recovers.

Benefits

  • Increases system reliability.
  • Reduces need for manual resets.
  • Essential for unattended or remote systems.

Example (C for STM32)

#include "stm32f4xx.h"

void WDT_Init(void) {
    IWDG->KR = 0x5555;        // Enable write access
    IWDG->PR = 0x06;          // Prescaler
    IWDG->RLR = 4095;         // Reload value
    IWDG->KR = 0xAAAA;        // Reload counter
    IWDG->KR = 0xCCCC;        // Start WDT
}

void Feed_WDT(void) {
    IWDG->KR = 0xAAAA;        // Reload counter
}

int main(void) {
    WDT_Init();
    while(1) {
        // Application code
        Feed_WDT(); // Reset watchdog timer
    }
}

Memories in Microcontrollers

Volatile and Non-volatile memory

Generally, memory are two categories

  • Non Volatile Memory – The contents of the memory are not permanently deleted while power is on and Off. It is often found in USB flash drives, MP3 players, digital cameras, and solid-state drives.
  • Volatile Memory – The contents of the memory are permanently deleted while power is on and Off.

which means that when the power is shut off, the contents of the memory are NOT lost

The main categories in Microcontroller are three type

  • Flash memory
  • RAM
  • EEPROM memory

Flash memory

Flash memory is used to store the program. It can be electronically reprogrammed and erased. Flash memory is a type of electronically erasable programmable read-only memory (EEPROM), but may also be a standalone memory storage device such as a USB drive. It is Non-volatile memory.

RAM Memory

The abbreviation of RAM is Random Access Memory. RAM is used to store the local variables during program execution time. RAM memory is helping to fast read access during the execution time. It is volatile memory.

Many type of RAM is available

  • SRAM,
  • DRAM and etc.

EEPROM

The Abbreviation of EEPROM is Electrically Erasable Programmable Read-Only Memory. Itโ€™s used to permanently store data like device Parameters, Errors, Timestamps, Sensor data, etc (As per project required). When compare to FLASH and RAM, the EEPROM is a slow response while accessing when execution. It’s non-volatile memory same as FLASH.

Memory Swapping Concept

In modern ARM cortex R series (TMS570LC4357- ARM Cortex R5F) have feature like swapping of the CPU instruction memory (flash) and data memory (RAM).

For example : controller flash memeory start from 0x00000000 and RAM start from 0x08000000. By default, CPU starts RAM memory from 0x08000000. But After swapping, the data RAM is accessed starting from 0x00000000, and flash memory is now accessed starting from 0x08000000. For this need to properly configure the settings in the respective register.

Difference between 8 bit, 16 Bit, 32 Bit, 64 Bit Microcontrollers

ControllersInternal BusALU OperationsFamilyPrecision
8 Bit8 Bits8 Bits8051, AVR, PIC, HSC121Byte
16 Bit16 Bits16 BitsExtended 8051XA, Intel 8096, MC68HC12, PIC16F2Bytes or Half word

Its greater precision than 8 bits
32 Bit32 Bits32 BitsARM, PIC32, Intel 80960, Intel/Atmel 251 Family, TMS570LC43570, ESP32 and ESP8266.4Bytes or Word

Its greater precision than 16 bits
64 Bit64 Bits64 BitsARM Cortex-R82 (Launched at 2020)8Bytes

Its greater precision than 32 bits

Bootloader

The bootloader is a piece of code that runs before, any operating system is running. Bootloaders are used to boot other operating systems, usually, each operating system has a set of bootloaders specific for it. Bootloaders usually contain several ways to boot the OS kernel and also contain commands for debugging and/or modifying the kernel environment. Bootloaders are used to boot other operating systems, usually, each operating system has a set of bootloaders specific for it.

Primary Bootloader
The detailed operation of the primary bootloader is device-specific. Some devices have complex capabilities such as booting from an I/O peripheral or configuring memory controller parameters.

Secondary Bootloader
The hex converter assumes the secondary bootloader is of a particular format. The hex converter’s model bootloader uses a boot table. You can use whatever format you want, but if you follow this model, the hex converter can create the boot table automatically.

Primary and Secondary boot-loader Sequence

The _c_int00 Function

The function _c_int00 is the startup routine (also called the boot routine) for C/C++ programs. It performs all the steps necessary for a C/C++ program to initialize itself.

The name _c_int00 means that it is the interrupt handler for interrupt number 0, RESET, and that it sets up the C environment. Its name need not be exactly _c_int00, but the linker sets _c_int00 as the entry point for C programs by default. The compiler’s run-time-support library provides a default implementation of _c_int00.

The startup routine is responsible for performing the following actions:

  1. Switch to user mode and set up the user mode stack
  2. Set up status and configuration registers
  3. Set up the stack
  4. Process special binit copy table, if present
  5. Process the run-time initialization table to autoinitialize global variables (when using the --rom_model option)
  6. Call all global constructors
  7. Call the function main
  8. Call exit when main returns

Intel Hex File Format

  •  Intel-Standard Hex file format is one of the commonly used formats in the microcontroller world
  • This standard is used to burn the 8051/52 program into an EPROM, PROM, etc,
  • 8051 Assembler generates the Intel Standard Hex file, it can be loaded into EPROM programmer.
  • Intel HEX is a file format that conveys binary information in ASCII text form.
  • It is commonly used for programming microcontrollers, EPROMs, and other types of programmable logic devices.
  • In a typical application, a compiler or assembler converts a program’s source code (such as in C or assembly language) to machine code and outputs it into a HEX file.
  • The HEX file is then imported by a programmer to “burn” the machine code into a ROM, or is transferred to the target system for loading and execution.

Below is the format of the intel Hex file

  • Position: 1 – Record Marker.
  • Position: 2-3 – Record Length.
  • Position: 4-7 – Address.
  • Position: 8-9 – Record Type.
  • Position: 10-? – Data Type.
  • Last 2 Characters: Checksum.

The below table is an example of 0300300002337A1E

Position: 1Record Marker03 (3 Byte of Data)
Position : 2-3Record Length0030(3 Bytes will be stored at 0030, 0031, and 0032)
Position: 4-7 Address00 (Normal data)
Position : 8-9Record Type02,33, 7A.
Position: 10-?Data Type1E
Last 2 CharacterChecksum.

GSM

Embedded Product Design

  1. Understand and analyze customer and design requirements to identify any gaps or missing information needed to perform development and testing activities
  2. Participate in high-level design for projects that have a high reuse factor
  3. Design software components based on the high-level design requirements
  4. Develop integration test plans and test cases to verify that the software meets the customer and the high-level requirements
  5. Test cases planning & Execution of test plans
  6. Analysis of executed test plans, and confirming that the software behavior respects the requirement documents
  7. Report findings (SW Bugs) on the configuration management tool
  8. Prepare test reports
  9. Perform the responsibilities of the previous technical level as per the project need
  10. Perform technical reviews on software component design, code, and test
  11. Continuously communicate work progress through attendance of daily & weekly project meetings. (Internal and external with other Value sites)
  12. Support his/her colleagues whenever required

in short for

  • Block Diagram
  • Design Circuit Diagram
  • Select Correct Component
  • Resistor
  • Capacitor
  • Diode
  • Encloser Box

Embedded Real-Time Applications

Elevators (Lift)

Manufacture companies

  • Kone (Fourth largest elevator manufacturer in the world. is also the pioneer of the machine room-less elevator system)
  • Johns & Waygood (Acquired by Perry Engineering in the 1970s)
  • Mitsubishi – Elevator
  • Schindler (Second largest elevator manufacturer in the world, and the largest escalator manufacturer in the world)

Reference

Reference

Interrupt logic?

In an embedded system, interrupt logic is the mechanism that allows the processor to pause the current execution and jump to a specific Interrupt Service Routine (ISR) when a particular event occurs.

Hereโ€™s the basic logic flow:

StepDescriptionExample
1. Event OccursA hardware or software event triggers the interrupt request (IRQ).Button press, timer overflow, UART receive
2. CPU Detects InterruptThe interrupt controller signals the CPU that an interrupt has occurred.NVIC in ARM Cortex-M
3. Save ContextCPU stores the current program counter (PC) and status registers.Saves execution state
4. Jump to ISRCPU executes the ISR linked to that interrupt.void TIM1_IRQHandler(void)
5. ISR ExecutesHandles the event quickly (minimal code).Read sensor data, clear flag
6. Restore ContextCPU restores saved state.Resume main code
7. Resume Main CodeCPU continues from where it left off.Main loop resumes

Key Points:

  • Interrupt Priority: Higher-priority interrupts can interrupt lower-priority ones.
  • Edge vs Level Triggered: Triggered by a change (edge) or constant state (level).
  • Masking: You can enable/disable specific interrupts.
  • ISR Rules:
    • Keep it short and fast.
    • Avoid printf or heavy processing.
    • Clear interrupt flags inside ISR.

Interrupt Latency

Interrupt Latency in embedded systems means: The time delay between the occurrence of an interrupt request and the start of the interrupt service routine (ISR) execution.


Why it happens

This delay comes from:

  1. Current instruction execution time โ€“ CPU finishes the instruction in progress.
  2. Interrupt disabling โ€“ If interrupts are temporarily disabled in code.
  3. Interrupt priority checking โ€“ CPU checks which interrupt has higher priority.
  4. Context saving โ€“ Registers and program counter are saved before jumping to ISR.

Example

If a button press triggers an interrupt:

  • Button press โ†’ CPU takes a few microseconds to finish the current task โ†’ Saves state โ†’ Starts ISR.
    That few microseconds = Interrupt Latency.

Minimizing Interrupt Latency

  • Keep critical sections (where interrupts are disabled) short.
  • Use faster processors or instructions.
  • Prioritize interrupts properly.
  • Keep ISRs short and efficient.

  Flow Chart

Flowcharts will help to understand the workflow. Flow is a type of diagram to easily identify the workflow or process. In flow chart have many different symbol shapes that are used to represent different kind of process or workflow.

  • Terminator
  • Decision
  • Process
  • Circle

Code Revision Tools

  • TortoiseSVN,
  • GIT
  • IBM Synergy.

What is Traceability Matrix Table?

  • Answere will add soon
Please turn AdBlock off, and continue learning

Notice for AdBlock users

Please turn AdBlock off
Index