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:
- D-Flip Flop
- T- Flip Flop
- SR- Flip Flop
- 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:
- 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.
- 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.
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.
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
- SDA: For sending bits
- 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
- In the end, if you want to use two devices then UART works best and fastest.
- If you have multiple slaves and one master then I would suggest going for SPI
- 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
About IoT
FlexCAN Peripheral Software Stack Explanation using NXP S32K144 MCU
FlexCAN Driver of CAN Peripheral in NXP S32K1xx and S32K3xx MCU’s, Understanding and tutorial using ElecronicsV3 Development board
ADC(Analog To Digital Converter) in STM32F103
Home Category Child Category Introduction Imagine that we are building a robot or an interactive art piece. We might be interested in measuring temperature, distance to the nearest object, force, and acceleration, sound pressure level, brightness, or any other physical characteristics. The first step is to convert all these physical quantities into a voltage using a transducer. The world is analog in nature, so every quantity that we need to measure is measured by the transducer in an analog output. But our Computers, MCU, Processors are digital in nature, that is they can Understand only ‘1’ and ‘0’. Thus we need an interface that can convert analog values of the world into digital values so as to process them. Thus here comes the ADC(Analog to Digital converter) “Analog Signals need to be processed correctly before they can be converted into digital form. This processinbg of Analog Signal is done by Signal Conditioning circuits” Important Terms in ADC Resolution of ADC: As said, ADC transforms an analog voltage to a binary number(series of 1’s &0’s) which is then represented as a Digital Number over our screens. The Number of Binary digits (1 &0) that represents the Digital Number determines the ADC Resolution ADC Introduction in STM32 Like every modern family of MCU, STM32 too has inbuilt ADC. Now if we open the datasheet of STM32F103 Bluepill and Navigate to its ADC Section. Now let’s break down this ADC Introduction part to understand the ADC Peripheral in STM32 MCU Successive Approximation: Type of ADC which is used in STM32 MCU.Which is made using OPAMPS, Resistors, Digital & Analog Electronic Circuit. So depending upon the type of circuit their are different types of ADC. 1) Successive Approximation 2) Sigma Delta 3) Voltage to frequency 4)Dual Slope ADC Analog Sensors & Electronics are huge topic, so wont be able to cover everything & would be focusing on STM32 MCU ADC Peripheral Click Here12 Bit ADC : Resolution of the ADC Peripheral in STM32 MCUThis is Resolution of the ADC Peripheral in STM32 MCU.Means Decoded ADC value which we will get will be ranging from [0-4095] = 2^12Click Here18 Multiplexed Channels: Blue Pill we have 18 ADC pinsBasically channels means from which Analog Values of the External world/Transducer will be fed to the MCU. Out of the 18 Pins Blue Pill has 16 external and 2 internal sources. This means that in 1) 16 pins [ADC0-15], we can fed analog values from the external world, like interfacing some analog sensors 2) 2 pins[ADC16:17] have the internal analog sources (Internal temperature Sensor & Internal Reference Voltage) : There is one inbuilt Temperature sensor inside the MCU which Outputs the data in analog value & send it to ADC_Channel 16.Click Here Previous Next So that is for the basic introduction of the ADC peripheral of STM32F103, now let\’s dive into more in-depth to know about the features of ADC peripheral in STM32 MCU. ADC Features in STM32 MCU Regular and Injected groups In STM32 MCU ADC peripheral their is a feature of Regular and Injected Group, we can configure the ADC Channels to be either in Regular Group or Injected Group. Regular Group: ADC Channels which are configured in regular group are converted regularly( when ADC peripheral is started by setting ADC_CR2:ADON bit), just like basic ADC conversion of channels one by one Injected Group: Now Channels which are configured in injected group works on same principal of Regular Group but this group have higher priorty then Regular group. As it names says injected, this group will interrupt the Regular group Conversion Click Here Types of Conversion Modes in STM32 ADCTheir are 4 types of Channel Conversion Modes in STM32. 1) Single Conversion Mode 2) Continuous Conversion Mode 3) Scan Mode 4) Discontinuous ModeClick HereSingle Conversion Mode: As it name says \”Single Conversion\” so when ADC peripheral is configured to be in Single Conversion Mode , only one time conversion of configured ADC channels is done when ADC peripheral is triggered.Click HereContinous Conversion Mode:As it name says \”Continuous Conversion\”, so this is vice versa of single conversion. All the configured ADC channels are continuously converted once the ADC Peripheral is triggered by Software or by external event and converted data is continuously stored in ADC_DRClick HereScan Mode:This is 3rd type of Mode, as its name says\”Scan\”. So when configured in this mode, ADC works like a \”SCAN\”, it is used to scan a regular or injected group channel. In short, we can say if we are using more than 1 ADC channel & doing conversion of all configured ADC channels then we will be using Scan Mode. After the first channel conversion, it will go to the next configured channel for its conversion till the last channel configured Click HereDiscontinous Mode:This is 4th type of mode, in this mode we can convert configured channels of regular and injected group in short sequences of n conversion (n
ADC Peripheral in S32K144
Explore about ADC Peripheral of Automotive MCU S32K1xx using ElecronicsV3 Board (S32K144 MCU) || ADC Channels || ADC HW&SW Triggering || ADC Pre Triggers || ADC relation with PDB and TRGMUX
About ARM Processor’s
first View What is a Processor Processor is programmable electronic circuitry that performs operations according to the instructions stored in memory. The processor as of itself does not have the memory and I/O devices. The processor reads the instructions stored in the memory, interprets it, and stores the output in memory or signals the I/Os. Processor Consists of the Processor core which contains circuitry for instruction fetching, decoding, and execution, register banks, and control units. According to the architecture design of the processor, the different processors have different components. For example, ARM cortex-M4 processors have NVIC, MPU, Floating point units, optional debug subsystems. This allows the microcontroller vendors to design differently. A block diagram of the microcontroller. Fig 1.2 – A microcontroller contains Many different blocks How does Processor control the world? Processors become an integral part of our life. We come across many devices which have processors embedded in them. For example: The smartphone on which I am writing this article has ARM cortex-A55 and cortex-A75 as processor, The Famous Tesla motors FSD Self-driving computer has many ARM processors. To give the idea of how processors are running the world look at these two examples. Upto 2019, Arm partners have shipped more than 160 billion Arm-based chips. Due to the shortage of semiconductor chips(processors) many car manufacturing companies had to reduce the number of cars manufactured. ARM Processor ARM Processor ARM processors are designed by ARM Ltd., ARM does not manufacture processors or sell the chips directly. Instead ARM licenses these designs to other semiconductor companies so that they can make their processor, microcontroller, SOCs as ARM processors are configurable. In the Cortex processor range, the processors are divided into three profiles: 1) The A Profile is designed to handle complex applications such as high-end embedded OSs. 2) The R profile processors are targeted primarily at the high end of the real-time market. These are applications, such as hard drive controllers, automotive systems, etc. 3) The M profile processors target smaller-scale applications such as microcontrollers and mixed-signal design. ARM CortexA1) The A Profile is designed to handle complex applications such as high-end embedded OSs.Click HereARM Cortex RThe R profile processors are targeted primarily at the high end of the real-time market. These are applications, such as hard drive controllers, automotive systems, etc.Click HereARM Cortex MThe M profile processors target smaller-scale applications such as microcontrollers and mixed-signal design.Click Here Previous Next ARM develops new processors, new instructions, and architectural features are added from time to time, as a result, there are different versions of the architecture. For example: ARM7TDMI is based on the architecture version ARMv4T. ARMv5TE architecture was introduced with the ARM9E processor families. With the ARM11 Processor family, the architecture was extended to ARMv6 with memory system features and SIMD instructions included. Cortex family processors are based on ARMv7 and ARMv6. The cortex-M3 and cortex-M4 processors are based on ARMv7-M architecture. The architecture evolution of the ARM can be seen in the following (Fig 1.4). All the cortex-M processors support Thumb-2 technology(16-bit and 32-bit instructions), with no need to switch the processor between Thumb state and ARM state. Keil MDK-ARMIAR systems(Embedded workbench for ARM Cortex-M) GCC_based IDEs Previous Next For Programming and debugging ARM Processor based MCU’s, we will be using Microcontrollers of different vendors like: STMicroelectronics and NXP Semiconductors. We will be using STM32 Family of STMicroelectronics and S32 Family of NXP Semiconductors. Both of these are based on ARM Processor and have rich set of features and specifications which are ideal for learning embedded systems. Now both the companies provide their own IDE’s for : STM32CubeIDE and S32 Design IDE for respective family of MCU mentioned above. Or we can also use the Above-mentioned IDE’s which are general IDE’s can be used to program any ARM processor based MCU. But recomended one is to use Vendor specific IDE as it has many extra featutes for programming. CMSIS The Common Microcontroller Software Interface Standard(CMSIS) was developed by ARM to allow microcontroller and software vendors to use a consistent software infrastructure to develop software solutions for cortex microcontrollers. THE AIM OF CMSIS: Software reusability: make it easier to reuse code with different Cortex-M processors, reducing time to market and verification efforts. Software compatibility: Due to consistent software infrastructure, software from various sources can work together, reducing the risk in integration. The CMSIS allows easy access to processor core features from the c language. CMSIS-compliant device drivers can be used with various compilation tools. CMSIS started out as a way to establish consistency in device-driver for the Cortex-M microcontrollers, and this has become CMSIS-Core. Since then, additional CMSIS projects have started: CMSIS-Core A set of APIs for applications developers to access the features on the Cortex-M processor regardless of microcontroller devices and toolchain used. CMSIS-DSP library This library is intended to allow software developers to create DSP applications on Cortex-M microcontrollers easily. CMSIS-SVD the System View Description in an XMl-based file format to describe peripheral set in microcontroller products. CMSIS-RTOS the CMSIS-RTOS is an API specification for embedded OS running on Cortex-M Microcontrollers. CMSIS-DAP the CMSIS-DAP(Debug Access Port) is a reference design for a debug interface adaptor, which supports USB to JTAG/Serial protocol conversions. The CMSIS files are integrated into device-driver library packages from the microcontroller vendor. So when you are using CMSIS-compliant device-driver libraries provided by the microcontroller vendors, you are already using CMSIS. We can define the CMSIS into multiple layers: Core peripheral Peripheral Layer Name definitions,address definitions, and helper functions to access core registers and core peripherals. This is processor specific and is provided by ARM. Device Peripheral Access LAyer: Name definitions, address definitions of peripheral registers etc. This is device specific. Access Functions For Peripherals Access Functions For Peripherals How do I use CMSIS-Core ? Add Source files to the project. This includes: Device specific, toolchain-specific startup code, in the form of assembly or C. Device-specific device initialization code(e.g. System_c). Add header files into the search path of the project: A device-specific header
Getting Started with S32 Design Studio Part 1
S32 Design Studio IDE Softwrae Installation and SDK installation for S32K144 MCU’s
Motor Control
When engineers are faced with the challenge of designing electrical equipment to perform mechanical tasks, they might think about how electrical signals get converted to energy. So actuators and motors are among the devices that convert electrical signals into motion. Motors exchange electrical energy to mechanical energy. To understand Motor terminologies Stator Rotor Armature Types of Motors A stepper motor is driven by pulses; it rotates through a specific angle (step) with each pulse. Because the rotation is precisely controlled by the number of pulses received, these motors are widely used to implement positional adjustments. They are often used, for example, to control paper feed in fax machines and printers—since these devices feed paper in fixed steps, which are easily correlated with pulse count. Pausing can also be easily controlled, as motor rotation stops instantly when the pulse signal is interrupted. About DC Motor The speed of a DC motor can be controlled by changing the voltage applied to the armature. Variable resistance in the armature circuit or field circuit allows speed control. Modern DC motors are often controlled by power electronics systems which adjust the voltage by “chopping” the DC current into on and off cycles which have an effective lower voltage. What is Brushless Direct Current Motor(BLDC) Author: Kunal Gupta
Author: Kunal Gupta
Author