Over 10 years we help companies reach their financial and branding goals. Engitech is a values-driven technology agency dedicated.

Gallery

Contacts

411 University St, Seattle, USA

engitech@oceanthemes.net

+1 -800-456-478-23

Embedded Basics Miscellaneous

Communication Protocol\’s in Embedded:

Table of Contents

Communication Protocols in Embedded System

  • Serial communication

In serial communication, we have only one line for transmitting and receiving data which is why it is half-duplex. It is best for high frequencies as it uses only a single bus or channel for communication, but it can be a bit slower than parallel as it sends only a single bit per clock pulse also because of the single wire here we have fewer chances of cross-talks. It can detect the error as well.

When transferring a bit quick change in voltage are required like for 5v OS, 0 bit communicated as a short pulse is 0v, and 1 bit communicated by a short pulse of 5v. In serial communication, the first bit is the most significant bit and the last one is the least significant bit.

  • Parallel Communication

In parallel communication, we have a number of lines or buses equal to the number of bits we are transferring. We call it full duplex as the line for transmitting and receiving bits is different. It is faster for small frequencies as all bits are sent at once but as we have to use multiple wires it is costlier also here, we have lots of chances of cross-talks.

As in serial, here also we have the first bit is the most significant bit and the last one is the least significant bit.

How do they convert?

The protocols we have read above communicate in serial form, but they get the data from their peripheral device in parallel form. How do bits get converted into serial form to parallel form? Suppose we have 4 bits, to convert them from parallel to serial we need a Parallel to Serial converter, In the same way, if we want to convert parallel from series, we need a serial to parallel converter. Here comes the D Flip-Flop which is specially designed for such conversions.

What is Flip-Flop?

A basic memory element or basic digital memory circuit is known as Flip-Flop. It is some medium in which one bit of information (1 or 0) can be stored or retained until it\’s necessary.

  • As one flip-flop can store one bit of information. To store multiple bits, we need multiple flip-flops.
  • The group of flip-flops, which are used to store the binary data is known as register.

Flip flop circuits are classified into four types based on their use:

  1. D-Flip Flop
  2. T- Flip Flop
  3. SR- Flip Flop
  4. JK- Flip Flop.

Here for conversion between Serial and parallel bits of data D-Flip Flop is used.

Now, what is D Flip-Flop?

D flip-flop is also known as Data or Delay Flip-Flop. It has a single D input and a clock input C which is why we call it a D flip-flop. Or for the word delay, it describes what happens to the data at input 0. The data at D input is delayed by one clock pulse before it gets to the output Q.

There are two different ways of conversions:

  1. Parallel to Serial conversion.
    • First, we need Flip-Flops equivalent to the number of bits. Then we will put the multiplexer in between the Flip-Flop.

    Multiplexer- It is a combinational circuit that takes input from one of many input lines(parallel) and directs it to a single output line(serial).

    It has two inputs:

    1) From the previous Flip-Flop

    2) From Parallel bit data.

    Now we will load the data which will be transferred one by one.Here msb will be transferred first.

  2. Serial to Parallel conversion.
  • First, we need Flip-Flops equivalent to the number of bits. This time we won\’t put the multiplexer in between the Flip-Flop.
  • We need to store all the bits at first for this we will pull the clock signal low. Once all bits are loaded, we will pull the clock signal high, and it will shift the LSB to the input of Flip-Flop 1 and output of Flip-Flop 0. Same way all bits gets transferred.
  • Now all the bits are stored in these Flip-Flop and as shown above all the Flip-Flop will transfer the bits at once the way it happens in parallel..

Overview about Serial Communication Protocols in MCU

UART Protocol

  • What is UART Protocol?

UART stands for Universal Asynchronous Receiver/Transmitter. As we can understand by the name it says it receives and transmits asynchronously. Asynchronously means it doesn\’t use clock pulse to synchronize the transmitter and the receiver.

In UART, the transmitter takes the signals in parallel from a controlling device[ex-CPU] then it sends the bits to a receiver in serial then the receiver converts those bits in parallel again. UART follows one master one slave approach as it uses only 2 wires for communication. It has one transmitter and one receiver.

  • How does it work?

As I, ve mentioned above it transmits asynchronously hence it uses a start and stops a bit, in it contains main data and a parity bit. The parity bit is only needed if the device needs to check the error.

When the device wants to start the communication, it pulls the transmitting line low which means it sends a 0 bit and receiving device understands that the transmitter wants to send the data. When the transmission line goes lows it stays low for one clock pulse and then it starts sending the data of 8 bits then the 9th one is a parity bit, the last one is stopping bit it stays high for the one clock pulse until the transmitter sends a low bit to start another frame.

To get, in detail understanding on UART Protocol, refer to this blog.

UART Protocol in Embedded System

SPI Protocol

  • What SPI Protocol is?

SPI stands for Serial Peripheral Interface. Just like UART it also uses Serial Communication for transmitting and receiving data but instead of asynchronous it uses synchronous communication protocol for transmission. 

Synchronous means the transmitter and the receiver must have the same clock signal. It uses a Full duplex communication protocol which means it can send and receive at the same time. SPI follows one Master multiple slave configuration.

  • This protocol has 4 parts

1. MOSI-Master Out Slave In

Here Master sends data to the slave and the slave receives the data. Master sends data to each device it is connected to via a single wire.

2. MISO-Master In slave out

Here Slave sends the data to the master and the master receives the Data. Master receives the data from each device it is connected to through a single wire.

3. CLK-Clock Signal

It is important for synchronizing the data when the master sends or receives it.

4. CS/SS-Chip select/slave select

We have different wires connected to the chips. Suppose we have 3 chips connected. Then the master would have three wires cs1,cs2,cs3 connected from chip1, chip2,chip3 individually.

To get in detail understanding on SPI Protocol, refer this blog.

SPI Communication in Embedded

I2C Protocol

I2C stands for the inter-integrated circuit. If you have read carefully about SPI and UART you will find I2C got the best features of these two.

It follows multi-master protocol as multiple masters through a single slave or to multiple slaves. It is a half-duplex communication protocol since it has only one line for transferring and receiving data. It is also called Two Wired Interface as it uses two wires for communication.

  • This protocol has 2 parts
  1. SDA: For sending bits
  2. SCL: For synchronizing the data.
  • How does it work?

In I2C as we have multiple slaves, every slave must have a different address before sending a bit master will address or call the receiver. If we have multiple masters then the master will check the clock signal. If it is high it will send the data or if it is low then it means another master is sending the data at the moment.

To get more in detail understanding of I2C protocol, refer to this blog.

 

Conclusion Para

  1.  In the end, if you want to use two devices then UART works best and fastest.
  2. If you have multiple slaves and one master then I would suggest going for SPI 
  3. And if you want to connect one slave with multiple masters then I2C is the fastest as it lowers the wirings as well.

Other blogs to explore

About Microcontrollers

What are Device driver, Application Codes and HAL in Embedded Softwares

What are Peripherals in MCU? What is peripheral driver in MCU? What is sensor/module interfacing in MCU. What is device driver and RTD? What is HAL/BSP? What is Application Software? When people start with Embedded Software development or Firmware development, there are couple of terms which they come across and found them very confusing to understand. Terms which i am targeting in this blog are like Device driver/low level drivers, Application codes, and HAL (Hardware Abstraction layer). To understand these terms, one has to understand that in Embedded systems there are hardware and Embedded Software is a software (take it as a programming) that is done to interact with different hardware devices. Now these hardware devices can be categorized broadly into input devices, processing devices and output devices. Input devices can be out and main These hardware devices would be like can be a complex software and s Device Driver –> First let’s breaks down the are the drivers that interface the 2 hardware’s. Real Time Drivers SDK HAL Application Codes BSP Abstraction layers Author: Kunal Gupta

Read More »
AVR MCU
Kunal Gupta

Getting started with AVR and Arduino

Home Category Child Category Part I – Untangling the wires: On your journey of exploring the different areas of embedded systems and microcontroller programming, you must’ve come across the term ‘AVR’. This blog (or series of blogs) will try to demystify all the terminologies. Prerequisites Before we proceed, this blog assumes that you already have a basic overview and understanding of what microcontrollers are, what their basic functionalities are, and how they differ from microprocessors. Knowledge of the C/CPP programming language would be beneficial. Table of Contents Introduction Arduino vs AVR The family of AVR microcontrollers Keywords Further reading References Introduction The technical definition of what AVR is, is: The AVR microcontroller is a family of mostly 8-bit microcontrollers developed by Atmel (now Microchip), that follow the Harvard RISC architecture. Let\’s try to break all this technical jargon down. Harvard architecture is a type of architecture where the instructions (program code) and data are stored in different parts of memory. This is in contrast to Von Neumann\’s architecture where no such distinction is made. The following illustration might help you understand the concept a little better. Now coming to the other piece of jargon that might’ve thrown you off RISC. It stands for Reduced Instruction Set-Computer. It is a computer architecture philosophy that generally follows the idea of having smaller and atomic instruction sizes when compared to its counterpart CISC (Complex Instruction Set-Computer), which has relatively bigger instructions. We won\’t be diving into this as this is a topic for another day. Arduino vs AVR Before we move any further let\’s clear one big misconception out of the way. People tend to confuse the terms Arduino and AVR quite often. Although it wouldn\’t be fair to compare these two (it would be like comparing an engine to a car), the following table clearly explains what are the differences between the two. In this article when we use the word “Arduino”, we will be referring to the Arduino platform which includes all the hardware and software made by the company.   Arduino   AVR 1. Is hardware and software platform which includes, but is not limited to: the Arduino IDE, Arduino Uno board, and the Arduino programming language 1. Is a family of microcontrollers developed in 1996 by Atmel. It is only a piece of hardware. 2. The Arduino Uno is a board that is built around the ATMega328, which is an AVR microcontroller. Apart from the microcontroller itself, it has other components such as a USB2.0 cable and a PCB on top of which the components such as resistors and capacitors are wired together. 2. Is a microcontroller that requires additional passive and active components (clock, LEDs, etc.) to be wired up by the end-user for it to work. 3. Products are developed and maintained by Arduino (company) 3. Products are developed and maintained by Microchip Technology Inc 4. An Arduino Uno board:Notice the various components such as voltage regulators, connectors, switches, LEDs that are already soldered onto the board.The rectangular black IC (Integrated Circuit)/chip on the bottom right-hand corner of the board is the engine that drives the car (board), ie, the ATmega328, which is an AVR microcontroller 4. The ATmega328P, an AVR microcontroller: It doesn’t come packaged with any components, which have to be attached by the vendor/programmer themselves Difference Between Arduino and AVR The family of AVR microcontrollers Microchip offers a wide selection of microcontrollers to choose from, each meeting a different set of requirements. They can broadly be divided into three categories. Series Package size FlashSize  Operating Frequency Example ATtiny(TinyAVR) 8-32 pins 0.5kB – 32kB 1.6MHz-32Mhz ATtiny85 ATMega(megaAVR) 28-100 pins 4kB – 256kB 1.6MHz-32Mhz ATMega328 ATxmegaXMEGA 44-100pins 16kB – 256kB 1.6MHz-32Mhz ATXmega128 AVR MCU Family Series Differences The above table isn’t exhaustive as there are many other families of microcontrollers such as the 32-bit AVR32 and the newly released AVR Dx series. The family of microcontrollers you end up choosing, totally depends on the scope of your project. Looking for a very small compact and lower power microcontroller which can automate a basic task, like toggling an LED-based on an input switch? Then go for the ATtiny family. Looking to control a servo motor that is connected to an IR sensor? You definitely won\’t go wrong with the ATmega series. Still, looking for more firepower for controlling multiple sensors? The ATxmega series has got your back. In the upcoming blog, we shall deep dive into one of the most widely loved and used microcontrollers – the humble yet mighty ATmega328. Till next time! Ciao! Further Reading http://ce.sharif.edu/~pourmohammadi/AVR%20Microcontroller%20and%20Embedded%20Systems/AVR%20Microcontroller%20and%20Embedded%20Systems.pdf https://en.wikipedia.org/wiki/AVR_microcontrollers http://www.avrbeginners.net/ References https://www.microchip.com/en-us/product/ATmega328P Intro Video on Device Drivers and Application Code for AVR(Arduino Boards) – YouTube Author: Kunal Gupta

Read More »

Clock Peripheral in STM32F103

Clock Peripheral Theory Before getting into how to configure the clock peripheral . We will discuss why microcontrollers need a clock source at all. The processor , the busses and the peripherals that are present in the microcontroller all are reliant on the clock to synchronize their operations. The choice of the clock source depends upon the following factors:- How much speed is required for a particular application How accurate the clock source should be i.e the consistency of the period between each clock tick Power requirements of the application If there is any significant error in the clock speed it will cause unpredictable consequences for internal microcontroller operations.The operations such as:- The conversion rate of analog to digital signals is governed by a microcontroller clock . The clock determines the rate at which the analog signal will be sampled and how accurate that sampling is done is also governed by the accuracy of the clock. The digital to analog conversion in a microcontroller is also dependent on the clock as the clock speed determines the maximum frequency that can be generated for the analog signal. Also the clock accuracy determines the waveform accuracy In the case of asynchronous communication the sampling of the incoming data stream is clock dependent as well.Even though in some cases the synchronization of the clock is not necessary but the transmitter and receiver should have the same clock speed for decoding and encoding purposes. So in a nutshell the clock determines how fast a microprocessor executes the given set of instructions Clock Peipheral features in STM32F103 The main system clock of the microcontroller is the one from which all the other clocks are derived such as clock to AHB domain, clock to APB domain , clock to the USB, clock to the ethernet etc .  This main system clock is referred to as the SYSCLK. As can be seen in the picture of the clock configuration setting the system clock after being chosen is passed through prescalers  it gets divided into a clock source that goes into HCLK that goes into  AHB bus , DMA , cortex system timer ,FCLK. PCLK1 that goes into  APB1 peripherals and timer clocks .PCLK2 that goes into APB2 peripherals and timer clocks and ADC1. Hence it is responsible for operations such as DMA , ADC. These buses are further connected to the pins that are responsible for ADC , GPIO , SPI and other functionality and in case these pins are not being used the clocks to the pin can be disabled to save power                                                             FIG-1- Clock configuration in stm32cube To properly drive the SYSCLK there are 3 different sources:- HIGH SPEED INTERNAL (HSI) oscillator clock(Internal to MCU) HIGH SPEED EXTERNAL (HSE) oscillator clock(External to MCU) PHASE LOCKED LOOP(PLL) clock( Internal to MCU) There are secondary clock sources as well:- 40KHz low speed internal RC (LSI)  this used to drive watchdog and optionally RTC(Internal to MCU) 32.768 KHz low speed external crystal (LSE)  which drives the RTCclock (RTCCLK) the error involved the LSE is less compared to the LSI( External to MCU) By default the HSI is ON in the microcontroller whereas all the other clocks HSE, PLL etc are OFF. Each clock source can be switched ON or OFF independently when not in use to prevent unnecessary power consumption. HSI HSI is the default SYSCLK after startup from RESET state, wakeup from STOP OR STAND BY mode or failure of HSE. It is a low cost clock source having a start-up time less than HSE. The maximum frequency that can be generated is 8MHz using HSI. It suffers from the demerit that it is less accurate than external crystal oscillator or ceramic resonator Also as the temperature increases above 25 degree celsius the accuracy decreases HSE In case of high speed application HSE can be used as a clock source for SYSCLK . The HSE or the high speed external clock is an external clock that sometimes comes attached to the microcontroller itself or at times requires the usage of an external circuitry. HSE is faster and more accurate than HSI but suffers from demerits such as slower startup time, high power consumption and times usage of an external circuitry The maximum frequency that can be generated using HSE clock is 16MHz HSE  has 3 states ON , OFF and BYPASS BYPASS is basically  connecting wire to OSC_IN and putting the OSC_OUT in high impedance state i.e bypassing the crystal oscillator as can be seen in FIG-2 external source  FIG-2 BYPASS mode in HSE PLL The PLL or phase locked loop is a clock system that is capable of providing the clock frequency much higher than that of HSI or HSE i.e in case of stm32f1 series it can go up to 72Mhz Hence for high speed applications PLL is a go to choice . Also peripherals such as USB, Ethernet PHY can not work using HSI or HSE. PLL provides the flexibility of choosing clock frequency without the help of an external oscillator. SYSTICK clock  The SYSTICK is required to generate interrupts on a regular basis . It helps the OS in multitasking applications .In applications without an OS is used for timekeeping, time measurement or as an interrupt source. It is derived from the system clock in stm32 and has an usual value of 16MHz. Which means is to generate a delay of 1sec 16000000 has to be loaded on SysTick load value register Clock peripheral HDK in STM32F103 external oscillator pins MCO pins Clock peripheral SDK in STm32F103 Clock peipheral Files in STM32HAL: CLock peripheral low level files and HAL level files Fucntions descritption and structure decsritption Clock Peripheral HAL Functions HAL_RCC_OscConfig: return type HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) Parameter arguments explanation and return type explanantion Argument 1 Argument 2 argument 3 return type //Demo of how to use functions Clock Peripheral HAL Data Types Data type name( structure name): //Code of that structure Tab #1 Tab #2 Tab #1 Lorem ipsum dolor sit amet, consectetur

Read More »

What is E/E Architecture in Automotive

Overview In a car at a time more than 100 small or large electronic subsystems are present. Most of these subsystems are connected directly or indirectly in one way or another. Now virtualize that this is a car and it has an Airbag control system which is controlled according to the vehicle motion monitoring system. If Vehicle motion experiences a sudden break or impact, the Airbag control system will be turned on. For understanding, let’s say the Airbag control system is Node A and the Vehicle motion monitoring system is Node B. Node B is situated at the front of the car and Node A is distributed on every seat of the vehicle. So Node B and Node A are connected directly to each other. But let’s say now there is one more Node C. Node C is a car Backlight. Now Node C and Node B are connected in a way if the vehicle motion experiences a sudden break then the car’s backlight has to be turned on immediately. As Car’s backlight is at the back, Node C is at the back of Car and Node B is at the front of the car, so we have to connect Node C and Node B also. Now wiring to connect to Node B and Node C would be required more to take it from front to back. Whereas if we place Node B at the center of the car, then the connection of Node A and Node C would be comparatively easy to do and fewer wires would be used. You can see the electronic subsystems used in cars are distributed across the vehicle. The arrangement of these electronic sub-systems, their architecture of placement and connection is what going to be the topic of today’s video. How the car electronic subsystems are connected, is what is gonna be the topic of today’s video. Surrounded by large-scale technological requirements (ADAS, connected vehicles, Software Defined Cars, Vehicle to Vehicle, Electrification, etc.) established OEMs and semiconductor companies are innovating and differentiating via the architecture designs for the arrangement of these electronic subsystems in a car.  In the last video/blog, we learned about different electronic/electrical sub-systems that are there in the car. Now we are going to dwell on architecture on how the different electronic/electrical sub-systems are arranged in an automotive vehicle. What is E/E Architecture E/E architecture is the terminology for arrangmant of elecrical/electromcnis used in car. E/E Architecture organizes and integrates a vehicle’s electrical and electronic systems, including hardware and software components, to ensure they all work together seamlessly. E/E Architecture involves the design of the arrangement of electrical and electronic systems that control various functions of a vehicle, such as a powertrain, safety systems, infotainment, climate control and etc. E/E architecture is also termed as vehicle architecture. The E/E architecture is an arrangement of different components of a vehicle, all combine to make up the vehicle architecture. These components are : 1) electronics hardware 2) network communications 3) software applications, and 4) wiring involved to connect different electric/electrical sub-parts of the system. Why is E/E Architecture or Vehicle Architecture needed? Okay so now we have understand what is E/E architecture, now lets dwell into why do we need E/E architecture concept in automotive vehicle;s. Integration of computing technology into every aspect of the car has transformed how automotive OEMs approach design, engineering and manufacturing of automotive electrical sub-systems. Concurrently, the introduction of sensors into the vehicle architecture further accelerated the need for greater computing power to process and analyze the resulting data. The advancement toward connected cars led to a divergence in how carmakers approached the communication architecture of a vehicle’s electronics. The result of this innovation and integration is a tremendously complex system of electronic control units (ECUs), sensors, actuators, and wiring to connect it all together. The size and complexity of these architectures create new challenges for automotive OEMs and their suppliers. In this environment, the importance of the underlying E/E architecture is paramount. The new generation of automotive consumers expect constant internet connectivity, a fully customizable driving or riding experience, as well as personalized entertainment and functionalities. Simultaneously, consumers expect to feel safe and secure, while enjoying the latest, modern features on-demand, in real-time and over-the-air as they download different applications and services from vehicle “app-stores”. In fact, the vehicle is no longer the focal point in the consumer’s mind, rather it is the mobility service or mobility experience that it provides. Different aspects of E/E architecture are sensors, microcontrollers/processors, networking protocols, wiring and power distribution. All aspects of the E/E architecture occupy a larger role in enabling core vehicle functionalities. As a result, all aspects have grown in sophistication to meet these increased demands. Microcontrollers/processors have become more powerful to process the data coming in from larger sensor arrays using increasingly capable software. Meanwhile, vehicle networks have to manage the communications in this intricate system of sensors and controllers. The result of these innovations and integration is a tremendously complex system of electronic control units (ECUs), sensors, actuators, and wiring to connect it all together. The size and complexity of these electrical/electronic subsystems create new challenges for automotive OEMs and their suppliers. These challenges will only become more intense as companies continue to advance vehicle technologies, particularly in the automated driving space. In this environment, the importance of the underlying E/E architecture is paramount. Surrounded by large-scale technological change, have forced established OEMs to innovate and differentiate via the E/E architecture for automotive sub-systems. This means creating architectures that are scalable across vehicle platforms, flexible to future technologies, and reliable over extended lives in the field. Types of E/E Architecture There are 3 types of E/E architecture in automotive: Flat architecture Domain Architecture Zonal Architecture Up until the past decade, vehicle electronics used a flat architecture where embedded ECUs operated together in a limited way. Flat Architecture: In the context of automotive electronics, a flat architecture refers to a system where embedded electronic control units (ECUs) act

Read More »
Kunal Gupta
Author: Kunal Gupta

Author

Kunal Gupta

Leave a comment

Stay Updated With Us

Error: Contact form not found.

      Blog