Posts

Showing posts with the label Embedded C

Getting Started with I2C: What is Clock Stretching?

Image
In  I2C(Inter-Integrated Circuit)   communication , the   master  device initiates the communication by sending a   start condition   and then sending the   slave device’s address . The slave device then responds with an   ACK   (acknowledge) signal to indicate that it has received the address correctly. If the slave device needs more time to process the data, it can hold the clock signal low to pause the communication temporarily. This is known as   clock stretching . Clock stretching is a technique used in communication protocols to allow slower devices to slow down the clock signal of a faster device. This technique is commonly used in I2C communication, where the clock stretching is performed by the slave device. This is useful in scenarios where multiple devices of different speeds are connected to the same bus. However, clock stretching can also cause  timing issues  if not implemented correctly. If the slave device holds...

How Interrupt Works ?

Image
  In an Embedded System , a Microcontroller or Microprocessor uses the Input/Output pins to interact with the outer world and the other devices. Output pins take the data or information out and input pins to read the data or information. Software on the microprocessor runs at a very high speed than the hardware interactions. A few milliseconds of delay with the hardware could be thousands of instructions for the software. So for optimal hardware and software interaction, there is a mechanism called interrupts. An interrupt is a signal that temporarily halts the normal execution of a program and directs the MCU to execute a specific piece of code, called an interrupt handler or interrupt service routine (ISR) . Interrupts are typically triggered by external events, such as a button press, a sensor reading, or a timer expiration. Interrupt Sources can be classified into two main categories : Internal interrupt: sources are generated by the MCU itself, such as a timer overflow or...

What is DMA?

Image
DMA is a technique that allows data to be transferred between devices without the intervention of the CPU. In a typical computer system, data is transferred from one device to another via the CPU . The CPU initiates the transfer, reads data from one device, and writes it to another device. This process can be time-consuming and takes up valuable CPU time, which can slow down the system. It eliminates the need for the CPU to be involved in data transfer by allowing data to be transferred directly between devices. These controllers can be built into the devices or added as a separate component to the system. The DMA controller operates independently of the CPU and uses its own memory address and data buses to transfer data between devices. The DMA controller is programmed by the CPU to read data from one device and write it to another. The DMA controller can transfer data in blocks, making the process faster and more efficient. When the CPU needs to transfer data, it initiates the tran...

What is a start-up code in an MCU?

Image
Start Up code of an MCU Starting up an MCU (Microcontroller Unit) involves executing a sequence of instructions that initializes the various on-chip peripherals and sets up the processor’s operating environment. This sequence of instructions is often referred to as the “startup code"  and is typically provided as part of the development tools provided by the chip manufacturer. The startup code is responsible for configuring several hardware and software aspects of the MCU to prepare it for the application code to run. Details of these tasks is as below: Stack Pointer Initialization : Stack Pointer points to the memory location in RAM which will be used by the program to store the function call stacks and the local variables for each function call. Data Section Initialization : Data Section in the memory layout contains the initialized global and static variables. Block Started by symbol (BSS) Initialization : BSS Section in the memory layout contains uninitialized global and sta...