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 MCU's Getting Started and Peripheral Coding STM32 MCU's

How to Use Trace Features in STM32 with STLINKv2 in CubeIDE

Table of Contents

Overview

Okay so hello guys and hope u are doing great; in the last 2 Blogs we get to know about Debug Trace Features in Embedded Systems and about ARM CoreSight Architecture for Debug and Trace in ARM based SoC/MCU.

Now, in this Blog we will implement the theoretical knowledge of previous blogs to action and do them practically! We will do so by exploring the Trace Features in STM32MCU practically (STM32F103 Blue pill) using STLINKv2-B ( Official one white one) in STM32CubeIDE. 

This Topic has been divided into 2 Blogs.

In this Blog Hardware connections between STLINKv2-STM32MCU  and Code Generation is explained. The Video For that is also Uploaded on Gettobyte YouTube channel here.

In next Blog How to use Trace Features using SWV is explained. The Video for that too is Uploaded on Gettobyte YouTube Channel here.

Intro on STLINKv2 Programmers and Debuggers

Now STLINKv2 which you can see in the above image is different from USB based STLINKv2 Programmer and debugger( Chinese clone one). It is different in terms of more features and JTAG support for Debugging the Firmware’s. 

Original STLINKv2 can be used for Programming and Debugging Both STM8 and STM32 MCU. For STM8 it uses SWIM Protocol and for STM32 it has SWD, JTAG Communication Protocol and SWO pin for trace features.

In USB based STLINKv2 Programmer Chinese cloned one also both STM8 and STM32 MCU can be programmed and debugged. For STM8 it also uses SWI Protocol but for STM32 MCU it has only SWD Protocol and pins available.

For using the trace features, In USB based Chinese cloned one STLINKv2 (which is relatively cheaper than above STLINKv2) we must solder the 5V pin of Programmer by one of the pins of the onboard pin of the MCU used in Programmer. And it is a kind of long and Cumbersome Process. 

But in Official STLINKv2 which is shown in above pic, we do not have to solder any of the pins for using Trace Features, The Programmer has Pinout and dedicated pins for using Trace feature using (SWD + SWO pins) and it has JTAG Dedicated pins too for Doing Debugging .

Now as given u some comparisons between Official and Unofficial STLINKv2 Programmer and Debugger let us dive into some Practical Part. In the rest of the doc,  STLINKv2 programmer and Debugger will signify the Official white in one derivative which is shown in above pic.

Hardware Connections for STLINKv2 and MCU

The STLINKv2 Programmer comes in with following things as u open its Box.

  • Main STLINKv2 Programmer and Debugger
  •  
  • 20 Pin JTAG connector
  • USB 2.0 A to USB 2.0 Mini B
  • 2 x Connecting Cable for STM8 SWIM

Now coming to the pain Connections for connecting STM32 MCU with STLINKv2.
Programmer has the following pins for connecting it to STM32 MCU(Blue Circle).

These Pins have Pinout like these:

STLINKV2 Pinout

Right side from the Embarked Area (Orange Color), is pin 1 of the Programmer and then the pinout goes as shown in above pic.

Now the Essential Pins out of these 20 pins of the STLINKv2 programmer to Program and Debug STM32 MCU using ARM Proprietary SWD Protocol are only 5 pins.

  • SWIO/TMS(Pin 7) à SWD PIN
  • SWCLK/TCK(Pin 9) à SWD PIN
  • TDO/SWO(Pin 13) à SWO PIN
  • STM32 RESET(Pin 15) à RESET PIN
  • VCC(Pin1&2) à POWER PIN
  • GND(Below Horizontal line’s any pin can be used as GND except 2) à POWER PIN
STLINKV2 Connection for STM32

SWD Pins of STM32 MCU will be connected to SWD PIN if we want to only use Debugging features alongside Programming the Microcontroller. Like as shown in PIC. 

Now for Using the Trace Features we must connect one additional Pin from the Programmer to OUR Microcontroller and that is SWO Pin (13th pin) of Programmer to the Respective Trace SWO Pin Of our STM32 Microcontroller.

In STM32F103 SWO PIN is PB3 as shown in this schematic.

So, for Using Trace Features Connections will be like this.

SWO Connection for STM32

To be noted down:

  • Any pin from the below horizontal line except the VCC pin of that line can be taken as GND pin when using SWD/SWD+SWO pins and can be connected to GND pin of our STM32 MCU.
  •  Sometimes or in some Programmers we have to short all the VCC pins by Jumper wire for Proper connections or encase device isn’t able to power up MCU or Program it.
  •  In some cases, VCC pins 1&2 can be wrongly mapped in Some Programmer, and they can be at left hand side of the programmer that is at pins 19 and 20. So in case MCU does not Power up by above connections, then do not panic just change the VCC Pins and it might work out. ( This is in my case, so below pitcher is according to that)

Now so after successful Connections between STLINKv2 and STM32 MCU, Connect the USB cable between STLINKv2 and Laptop and LED light on the programmer will lighten up in RED color.

         Figure 5 (These are the Final Connections For SWD+SWO)

Software Part used

Now I will be Showing STM32CubeProgrammer and STM32Cube IDE In this blog in software part.

First with STM32CubeProgarmmer:

As u connect your STLINKv2 Programmer to your computer, IN STM32CubeProgrammer u will see the Serial Number of Programmer if all goes well. As shown in Pic.

Figure 6

Now as u click on Connect Button by selecting STLINK, u will see all the details of Your respective MCU details and showing its memory Content. (In doing so Your programmer will start blinking in red, green color and Screen of STM32CubeProgrammer might take 1-2 secs of time for showing Memory contents and MCU details.)

Figure 7

This is just Demonstration of Successful connections of STLINKv2 and MCU for SWO+SWO pins and established Communication between Programmer and Laptop via STM32Cube Programmer.

As if now, we have not used the trace features, for using that we must create a project and Upload in MCU by things mentioned in below section.

For STM32CubeIDE also follow the below section

If any Error comes in while connecting the STLINKV2 , FOLLOW  this video for solving all kinds of Errors and to get Solutions for them.

Code for using Trace Features in STM32 MCU

Create a New Project in STM32CubeIDE by choosing your corresponding Workspace (Figure 1), select Your MCU in Board Configuration Window (Figure2) by selecting the MCU you are using.

Figure 8

\"\"

Figure 9

Now name Your Project in next window and choose the targeted language according to your choice and Select Executable in Targeted Binary Type.

In Target Project type their will be 2 Options,

STM32Cube and Empty.

(In this Blog I will be telling things according to STM32cube project type. By selecting STM32Cube, Auto generated code STM 32 HAL initializes all the Processor registers for using Debug and Trace features according to the configurations made in STM32CubeMX window.)

Now in Cube MX configuration window we must Select RCC Mode for HSE as Crystal/Ceramic Resonator and Debug Mode as Serial Wire,

Under Pinout and Configuration window select the System Core and in it Select the RCC and SYS. Select the corresponding Options as shown in pics below.


Figure 10

And then in the clock Configuration window Select the Clock Frequency according to your choice. I am selecting 32Mhz in my case for STM32F103 using HSE (which has input frequency of 8 MHz and selecting PLL as clock Source for System clock).

I am configuring the Onboard LED on STM32F103 Blue Pill as GPIO OUTPUT just for demonstration purpose. That is pin PC13.

Figure 11

And then save the file and Autogenerated code Process using STM32HAL will be started.

Figure 12

Now open the main.c file of Your project from the Project explorer window.

Figure 13

That is all for this Blog, second part of the Topic is in next Blog.

Follow the next Part for NEXT Part of the blog.

Playlist for Debugging techniques in Firmware development: https://www.youtube.com/playlist?list=PLb_Q-Ps0nJou2Ped93q02JRfiMCJorLYX

Previous and Next Blog

Other blogs to explore

What is RFID technology? Applications, Working Principal, Types, Projects

Table of Contents What is RFID technology? RFID is a technology by which objects can be tracked and identified using electromagnetic fields. RFID stands for Radio Frequency Identification. An RFID system consists of an RFID reader known as a Proximity Coupling device (PCD) and RFID tags known as Proximity Integrated Circuit Cards (PICC). RFID Tags are attached to the objects which need to be tracked/identified and each tag has a unique value hard coded. RFID readers are attached to the main system/computer where all the processing takes place. Now, these tags are brought in close proximity to the RFID readers, RFID readers decode the value and send the information to the main system for tracking/identifying/monitoring purposes depending on the application. RFID technology is similar to a barcode or the magnetic stripe of a credit card, as the data encoded in the label or magnetic strip can be captured by a device and stored in a database. RFID belongs to a group of technologies referred to as automatic identification and data capture (AIDC). AIDC methods automatically identify objects, collect data about them and enter the data directly into systems with little or no human intervention. RFID methods use radio waves and automation technologies to accomplish all of this. This technology has grown a lot since its first application. It has not only been improved over the years but also the cost of implementing and utilizing it continues to minimize, making this technology more efficient and affordable. In its simplest form, an RFID system consists of 2 components: an RFID tag and an RFID reader. Refer to the section below to know more in-depth about RFID tags and Readers. RFID tags are used to track objects, by reading/writing information on them and are usually composed of an integrated circuit, antenna, and battery. The integrated circuit stores the data and powers the antenna, allowing it to be read by a reader. Tags contain digitally encoded information that is stored in the integrated circuit and is transmitted to the reader. Readers are devices that intercept, decode, and interpret the information stored in the tag. Typically, readers consist of RFID antennas, multiple operating modes (active and passive), frequency capabilities, and signal processing. The readers, antennas, and tags work together to collect data from RFID tags and transmit it to computer systems. RFID Reader (PCD) PCD(Proximity Coupling device): Also known as RFID readers. They decode the RFID Tags and communicate with them based on ISO14443 standard. PCD can perform read and write operation of data i.e bidirectional communication once PCD and PICC are coupled together. The coupling between PCD and PICC is based on inductive coupling (Refer to Working principle of RFID technology to know physics behind it).PCD energizes the PICC by coupling with them when PICC comes in close vicinity of PCD.And PICC gets energized, it starts transmitting its radio signals with UID of it. For energizing the PICC, they need to be brought in close proximity so that PCD magnetic fields get properly coupled with PICC. PCD’s have the memory(FIFO buffers, EEPROM), communication pins for Host Interface(I2C,SPI,UART), antenna for generating of radio signals, power supply, I/O pins(Interrupt and Timer pins), small CPU for processing of data(CRC,Interrupt controller, Timer unit), Analog interface for RF front head(oscillators, PLL, PGA and etc), Low power modes and support of multi protocols for decoding tags. PCD has the crypto features also implemented inside them, so that only authenticated RFID readers can communicate with PICC. And this also becomes the distinguishing feature in different PCD’s. Like NXP semiconductors, RFID readers follow the crypto-1 cipher for authenticating. Also some PCD’s have secure models and key handling capabilities for secure communication between PCD and PICC for banking and transaction related applications. There are many semiconductor companies who provide the RFID reader chips, with many enhanced features.NXP semiconductors and STMicroelectronics are world leaders in providing RFID reader chips. NXP semiconductors has a family of RFID/NFC chips with many enhanced features. For more indepth knowledge on PCD, viewers can refer to:Radio-frequency identification – Wikipedia. In the upcoming blog, we are going to interface NXP semiconductors MFRC522 and PN512 with host MCU. By making its device driver and to showcase the working of PCD’s RFID Tag(PICC) PICC (Proximity Integrated Circuit Card): These are the RFID Tags, which are known as Proximity Integrated Circuit cards, in technical terms. PICC are attached to the objects which need to be tracked. PICC consists of an antenna for generation of radio waves and memory for storing the UID and other information of PICC. Each PICC has a Unique value hardcoded inside them. This unique value is referred to as UID. The UID value is 7 bytes. PICC have memory divided in terms of blocks and sectors for storing the important information. There are mainly 2 types of PICC/RFID tags. Active tags and Passive tags. Active tags: They have on chip batteries; thus, they can operate at bigger distances and can operate at higher frequencies. Passive tags: They don’t have an on-chip battery, instead they get energized and get the power from the PCD’s.magnetic fields. Thus, Passive tags need to be brought in very close proximity to PCD of about 1-2 cm, for decoding its value. Also, tags are available in many different shapes, depending on the application. They come in credit card-based shapes, to small key ring-based shapes. Also, some tags have crypto features inside them for authentication purposes when PCD’s communicate with them. NXP semiconductor is a world leader in providing RFID Tag chips. Their MIFRAME family of RFID tags has been implemented in 1000’s of devices and use cases. PCD and PICC communicate with each other according to ISO14443 spec. There are certain commands specified in that protocol, which are at first transmitted by PCD’s and then corresponding PICC responds, and the communication session is initialized. For more in-depth knowledge on PICC, viewers can refer to:Radio-frequency identification – Wikipedia. NXP semiconductor is a world leader in providing RFID Tag chips. Their MIFRAME family of RFID tags

Read More »
Embedded MCU's
Kunal Gupta

How to Use Trace Features in STM32 with STLINKv2 in CubeIDE – Part 2

This is Follow up video of the previous Blog, In this How to use Trace features in STM32 MCU via SWV are explained using STLINKv2 Programmer and Debugger in STM32CubeIDE. Table of Contents Various Trace Features by SWV, Live Expressions and Using them SWV in STM32CubeIDE provide us with following Trace Features to be used in STM32MCU. Figure 14 SWV Features can only be used in Debug mode, so after creating your project as mentioned in below section, click on Debug Icon on the Menu bar of CubeIDE. Figure 15 If you are debugging your code for first time, debug configuration window will pop up, in which u must select your Debugger and made some Configurations. Main things to select in Debug Configuration window are. Debug Probe -> Select GDB server or OpenOCD. Enable the Serial wire Viewer(SWV) by checking on enable button and select the Core clock of SWV exactly as the Clock frequency that u have configured for your MCU system Clock, SWO clock as 2000 khz Under Misc. Section select the Enable Live Expressions Figure 16 Out of all SWV features I will be showing how to use marked SWV Trace Features from above pic of SWV Show View. SWV ITM Data Console So first Starting the SWV ITM Data Console which is used for printing printf() commands for printing Strings on the ITM terminal screen without using UART. For that We have to include the following code in your main.c file and include Header file Stdio.h in your main.c for printing the printf() commands on your ITM console. And now in your while loop of main.c file just write printf() commands like these. In the following Pic I have also blinked the led at PC13 pin. And then Debug the code by clicking on Debug Icon in Menu bar of CubeIDE. And after entering Debug Mode, click on Window -> Show View -> SWV -> SWV ITM Data console. Now as You open the SWV ITM Data Console, or any SWV window, u will find Following 2 icons in every view.  The first one is the SWV configuration Button, which is very important and configures our SWV. And another one is Start button for Starting the Trace. At first, we must do the SWV configurations, so click on first button. SWV Configuration window will pop out. Now For Using the ITM Data console, just click on the below marked check box for printing Printf() commands on the ITM port 0.and then click on ok.  Now start the trace by clicking on Red Button alongside the Configuration button. And now Resume the Code in Debug Mode only by clicking on the Resume button in menu bar of Cube IDE. Now as You click on Resume Button, U can see your printf() output strings on the ITM Data console. So that is how one can Print the strings using SWV + SWD in STM32 MCU via STLINKv2 without using UART for debugging the firmware. Click on Suspend button to stop the SWV. SWV Data Trace and SWV Data Trace Timeline Graph These two windows can be used to trace up to any Variables/Address locations of our code. Showing their value and other necessary details. For showing their use case, in our main.c I will be creating two variables by a&b. As shown in below pic. Now debug the code and open the SWV Data Trace and SWV Data Trace Timeline Graph windows. From those windows open the SWV configuration window as told in previous Section. And do the following changes, Enable the Comparator 0 and 1: one can data trace only up to 4 variables or address locations as you can see there are 4 Data Trace Comparators in our SWV Configuration window. In Var/Addr sections of Comparator 0&1 write the variables or address locations to be traced. And select ACCESS and GENERATE according to your variable being traced or address location being Traced. Below is the pic, showing my configurations: Click on okay and then start the Trace and Resume the Code in Debug Mode only as specified in Previous Section. Now you will see in SWV Data Trace view, all trace data of configured variables/address locations is being shown under History Section, showing various parameters like Value, Access, Program Counter value, Clock Cycles and Time for the Traced Event. As shown in Figure. Out of Configured Comparator, one can select for which comparator we want to see the history from the Watch section of Data trace, as shown in above Two pics.  Data trace data can be of great value for monitoring Time critical variables and address locations and observing their behavior during Program execution. In SWV Data Trace Timeline Graph, one can see the plotting of value of the configured Comparators in the form of graph and Analyzing Variables that are dependent on each other or Time critical. The Graph is plotted as shown in Pic. There are various options available on TimeLine Graph window, you can experiment those features by your won. SWV Statistical profiling Is used to see in which functions of your code, CPU is spending too much of time when program is running in MCU. To use SWV Statistical Profiling we do not have to write any code, just do as mentioned in Various Trace Features by SWV and Using them section above and enable the PC Sampling in SWV configuration window. Then start the trace and Resume the Code in Debug code as told in above sections. Now For Statistical Profiling wait for x number of secs after resuming your code according to your choice, in that time no data will be shown on Screen. After x amount, suspend the Program Execution and You will see something like this. As you can see, in above pic one can analyse in which functions our code is spending most of the and how much time. Which can be of great help in Very Complex codes which includes multiple I/O

Read More »

Introduction to STM32WB55

Table of Contents About STMicroelectronics STMicroelectronics is a leading provider of semiconductor solutions that are seamlessly integrated into billions of electronic devices used by people worldwide on a daily basis. The semiconductor company builds products, solutions, and ecosystems that enable smarter mobility, more efficient power and energy management, and the wide-scale deployment of the Internet of Things and connectivity technologies. To know more about STMicroelectronics refer to its website: www.st.com. Going back in history, ST was formed in 1987 by the merger of two government-owned semiconductor companies: Italian SGS Microelettronica (where SGS stands for Società Generale Semiconduttori, “Semiconductors’ General Company”), and French Thomson Semiconductors, the semiconductor arm of Thomson. In this blog, we are going to start with ST IoT-based Nucleo Board STm32WB55. What is STM32WB Series all about? The STM32WB55xx and STM32WB35xx are advanced multiprotocol wireless devices that boast ultra-low-power consumption. These devices are equipped with a powerful and efficient radio that is compliant with the Bluetooth® Low Energy SIG specification 5 and IEEE 802.15.4-2011 (Zigbee). Additionally, they feature a dedicated Arm® Cortex®-M0+ processor that handles all real-time low-layer operations. These cutting-edge devices are perfect for a wide range of applications that require reliable and efficient wireless communication. Whether you’re working on a smart home project, a wearable device, or an industrial automation system, the STM32WB55xx and STM32WB35xx are the ideal choices. With their advanced features and capabilities, these devices are sure to revolutionize the way we think about wireless communication. So why wait? Start exploring the possibilities today and discover what the STM32WB55xx and STM32WB35xx can do for you! The devices have been meticulously crafted to operate on minimal power and are built around the high-performance Arm® Cortex®-M4 32-bit RISC core, which can operate at a frequency of up to 64 MHz. This core boasts a Floating-point unit (FPU) single precision that supports all Arm® single-precision data-processing instructions and data types. Additionally, it is equipped with a full set of DSP instructions and a memory protection unit (MPU) that enhances application security. These devices have been designed with the utmost care and attention to detail, ensuring that they are not only efficient but also highly effective. The Arm® Cortex®-M4 32-bit RISC core is a powerful tool that enables these devices to perform at an exceptional level, while the FPU single precision and DSP instructions provide unparalleled accuracy and precision. Furthermore, the memory protection unit (MPU) ensures that your applications are secure and protected from any potential threats. Enhanced inter-processor communication is provided by the IPCC with six bidirectional channels. The HSEM provides hardware semaphores used to share common resources between the two processors. The devices embed high-speed memories (up to 1 Mbyte of flash memory for STM32WB55xx, up to 512 Kbytes for STM32WB35xx, up to 256 Kbytes of SRAM for STM32WB55xx, 96 Kbytes for STM32WB35xx), a Quad-SPI flash memory interface (available on all packages) and an extensive range of enhanced I/Os and peripherals.  About STM32WB55 Architecture Memories Security and Safety True random number generator (RNG) RF Subsystem Low Power Modes Clocks and Startup General Purpose Input Output(GPIOs) Direct Memory Access (DMA) Interrupts and Events Analog to Digital Convertor (ADC) Comparators (COMP) Touch Sensing Controller Liquid crystal display controller (LCD) Timers and watchdogs Real-time clock (RTC) and backup registers Inter Integrated Circuit (I2C) Universal Synchronous/Asynchronous Receiver Transmitter (USART) Serial Peripheral Interface(SPI) Serial audio interfaces (SAI) Quad-SPI memory interface (QUADSPI) Architecture Architecture STM32WB55 Architecture The host application is housed on an Arm® Cortex®-M4 CPU (named CPU1) that connects with a generic microcontroller subsystem. The RF subsystem is made up of a specialized Arm® Cortex®-M0+ microprocessor (named CPU2), Bluetooth Low Energy and 802.15.4 digital MAC blocks, an RF analog front end, and proprietary peripherals. All Bluetooth Low Energy and 802.15.4 low-layer stack functions are handled by the RF subsystem, which limits communication with the CPU1 to high-level exchanges. Some functions are shared between the RF subsystem CPU (CPU2) and the Host CPU (CPU1): Flash memories  SRAM1, SRAM2a, and SRAM2b (SRAM2a can be retained in Standby mode)  Security peripherals (RNG, AES1, PKA)  Clock RCC Power control (PWR) Memories Memories STM32WB55 Memories 2.1.  Adaptive real-time memory accelerator (ART Accelerator) The ART Accelerator is a memory accelerator optimized for STM32 industry-standard Arm® Cortex®-M4 processors. It balances the inherent performance advantage of the Arm® Cortex®-M4 over flash memory technologies. To release the processor near 80 DMIPS performance at 64 MHz, the accelerator implements an instruction prefetch queue and branch cache, which increases program execution speed from the 64-bit flash memory. Based on CoreMark benchmark, the performance achieved thanks to the ART accelerator is equivalent to 0 wait state program execution from flash memory at a CPU frequency up to 64 MHz. 2.2.  Memory protection unit In order to prevent one task from unintentionally corrupting the memory or resources used by any other active task, the memory protection unit (MPU) is used to manage the CPU1’s accesses to memory. This memory area is organized into up to eight protected areas. The MPU is especially helpful for applications where some critical or certified code must be protected against the misbehavior of other tasks. It is usually managed by an RTOS (real-time operating system). 2.3.  Embedded flash memory The STM32WB55xx and STM32WB35xx devices feature, respectively, up to 1 Mbyte and 512 Kbytes of embedded flash memory available for storing programs and data, as well as some customer keys. 2.4.  Embedded SRAM The STM32WB55xx devices feature up to 256 Kbytes of embedded SRAM, split in three blocks: SRAM1: up to 192 Kbytes mapped at address 0x2000 0000  SRAM2a: 32 Kbytes located at address 0x2003 0000 also mirrored at 0x1000 0000, with hardware parity check (this SRAM can be retained in Standby mode)  SRAM2b: 32 Kbytes located at address 0x2003 8000 (contiguous with SRAM2a) and mirrored at 0x1000 8000 with hardware parity check. Security and Safety Security and Safety The STM32WB55xx  contain many security blocks both for the Bluetooth Low Energy or IEEE 802.15.4 and the Host application. It includes:  Customer storage of the Bluetooth Low Energy and

Read More »

Silicon Labs Thunderbolt EFM32BG22

IDE To be used: Simplicity Studio – Silicon Labs (silabs.com) SDK to be used: Gecko Platform Silicon Labs (silabs.com) SDK documentation: EFR32BG22 Gecko MCU and Peripheral Software Documentation – v5.9 – MCU EFR32BG22 API Documentation Silicon Labs (silabs.com) HDK to be used:SLTB010A EFR32BG22 Thunderboard Kit – Silicon Labs (silabs.com) HDK manual: UG415: Thunderboard EFR32BG22 User’s Guide (silabs.com) Microcontroller datasheet: EFR32BG22C112 Wireless Gecko SoC Data Sheet (silabs.com) Microcontroller Reference manual: EFR32xG22 Wireless Gecko Reference Manual (silabs.com) Author: Kunal Gupta

Read More »

SPI Communication

Introduction to the SPI SPI stands for Serial Peripheral Interface. It is one of the most widely used interfaces between the microcontroller or other peripheral devices such as sensors, shift registers, etc. It uses a Synchronous communication protocol [It shares a clock signal for synchronizing bits between 2 devices] for the communication between a Master[ a microcontroller] and slaves[other peripheral devices]. Usually, a [Master]microcontroller sends a clock signal to the slaves to start the communication between them. SPI uses either 3 or 4 logic signals to communicate SCLK–  Shared clock signal      [Synchronize data transmission] MOSI–  Master Out Slave In      [Master sending data to the peripherals] MISO–  Master In Slave Out      [Master receiving data from the peripherals] CS/SS–Chip/Slave Select       [Master indicates that data is being sent] How do SPI works? CS/SS – To start a new transmission the Master pulls the chip select to a low voltage level which means taking the voltage to 0. When it’s done the chip select goes back to its non-transmitting state which is a high voltage level.  It is also used for selecting the slave to which master wants to communicate when we have multiple peripherals. When we have multiple slaves they are get connected by the Daisy chain. In Daisy Chain ChipSelect for all the slaves is connected together as in fig below and data propagates from one slave to the next. All the slaves receive the clock signal at the same time. Master sends the data to the first slave and so on. When the data is transferring from one slave to the next, The number of clock cycles required to transmit data is proportional to the slave position. Ex: Assuming we have 2 slaves and we need to transfer the data to the second slave. We have an 8-bit system then we need to send 16 clock pulses[8clockpulses at once as we are taking an 8-bit system] to get to the second slave.                            But Daisy Chain is not supported by all devices. Reading Data Sheet is recommended for that. SCLK – In SPI the clock signal is generated by the Master. The Master configures the clock, using a frequency supported by the slave device, and sends the clock signal to synchronize the data. Clock Polarity and Clock Phase are the main parameters to define a clock signal which is described later. MOSI/MISO – As SPI is full-duplex, the Master can transmit and receive the data bit by bit at the same time. Master sends the data in series usually MSB goes the first and in MISO, the slave sends the LSB first to the master. Modes of transmission CPOL[clock polarity]- It is used to determine the idle state of the clock. CPHA[clock phase]- Clock Phase determines at which edge data read/write occurs which is described in modes of transmission. If CPOL = 0 , data read/right occurs at falling edge then CPHA=0 If CPOL = 0 , data read/right occurs at rising edge then CPHA=1 If CPOL = 1 , data read/right occurs at rising edge then CPHA=0 If CPOL = 1 , data read/right occurs at falling edge then CPHA=1There are 4 modes of transmission in SPI: Data Transmission Steps The Master selects the chip select line associated with the slave. The Serial Clock line is then enabled. Master starts sending one bit of data on the MOSI line with each clock pulse. Slave reads the MSB first and stores it into memory. MISO line sends the data to the Master. Master reads the LSB first and stores it into the memory. Applications of SPI Memory: SD Card, MMC, EEPROM, Flash. Sensors: Temperature and Pressure. Control Devices: ADC, DAC, digital POTS, and Audio Codec. Others: Camera Lens Mount, touchscreen, LCD, RTC, video game controller, etc Author: Kunal Gupta

Read More »
Kunal Gupta
Author: Kunal Gupta

Author

Kunal Gupta

Leave a comment

Stay Updated With Us

Error: Contact form not found.

      Blog