4
New Automatic SPI Decoding Algorithm Roland Szabó Applied Electronics Department Fac. of Electronics and Telecom., “Politehnica” Un. Timişoara, România [email protected] Ioan Lie Applied Electronics Department Fac. of Electronics and Telecom., “Politehnica” Un. Timişoara, România [email protected] Abstract—In this paper is presented a new method how to decode SPI signals. The signals are viewed and acquisitioned with an oscilloscope, after that the signals is transferred to the PC through Ethernet interface and decoded with the application using this algorithm. SPI interface is quite commonly used for communication between microchips, because it has a simple protocol. Testing this communication can be done by decoding the SPI signals, which it’s quite an elaborate task to do it manually, this way a simple application which can do this can reduce a lot of time and effort. Keywords-acquisition, decoding, Ethernet, interface, oscilloscope, protocol, signal, SPI. I. INTRODUCTION This paper presents a new SPI decoding algorithm. SPI (Serial Peripheral Interface) bus is a synchronous serial data transmission. It was introduced by Motorola and it has full- duplex communication mode. Like other many communication protocols it has master/slave mode. The communication is made on 4 wires (Fig. 1); this way the algorithm is made on the 4 signals that are transferred from the oscilloscope to the PC. The 4 signals are named in a lot of ways, but the main idea is that we have a clock signal (CLK = Clock or SCLK = Serial Clock), two data signals (DI = Data In, DO = Data Out) and one enable signal, chip select or slave select signal ( EN = Enable, CS = Chip Select or SS = Slave Select), which shall select the slave to which the master will communicate, because this protocol allows more slaves. As we can see the enable signal has inverted logic, so it activates the slave on 0. Figure 1. SPI bus with Master and Slave II. PROBLEM FORMULATION We have a lot of development boards with microcontrollers, ASICs and other microchips. We wanted to test their functionality by sending and receiving commands on the SPI interface. The best way to test the SPI interface is to check the sent and received commands with oscilloscope and after decode them. We have oscilloscopes with big sample rate, high precision and high frequency. Our oscilloscopes had Windows installed on them and some of them had touch screens too, they are made by Tektronix and LeCroy, some of the best companies in this area. These companies already provide signal decoding modules for these oscilloscopes, but they are very expensive and because of the lack of budget we couldn’t buy them, so we decided to make our own decoding application. III. PROBLEM SOLUTION A. Hardware Setup We wanted to make simple application which can decode the SPI signals. The basic idea is we have 2 LabVIEW programs which acquisition the SPI signals from the two oscilloscopes (Tektronix and LeCroy) and save all the 4 signals in 4 different Excel files which have as many rows as the sample rate (ex. 50 kS = 50000 rows in the Excel file). The signal samples are one under another in different rows. The acquisition is done on Ethernet interface. The network was configured quite easily we used an internal IP address class that IANA (Internet Assigned Numbers Authority) provided. PC: IP address: 192.168.10.1 Subnet mask: 255.255.255.0 Oscilloscope: IP address:192.168.10.2 Subnet mask: 255.255.255.0 This way if we connect the PC with the oscilloscope using the cable and maybe reconfigure or deactivate the firewalls on the two systems we shall have the PC and the oscilloscope on CLK DI SPI DO Slave EN CLK SPI DI Master DO EN Legend: CLK=Clock DI=Data In DO=Data Out EN =Enable 978-1-4673-1176-2/12/$31.00 ©2012 IEEE

[IEEE 2012 10th International Symposium on Electronics and Telecommunications (ISETC) - Timisoara, Timis, Romania (2012.11.15-2012.11.16)] 2012 10th International Symposium on Electronics

  • Upload
    ioan

  • View
    213

  • Download
    1

Embed Size (px)

Citation preview

Page 1: [IEEE 2012 10th International Symposium on Electronics and Telecommunications (ISETC) - Timisoara, Timis, Romania (2012.11.15-2012.11.16)] 2012 10th International Symposium on Electronics

New Automatic SPI Decoding Algorithm

Roland Szabó

Applied Electronics Department

Fac. of Electronics and Telecom., “Politehnica” Un.

Timişoara, România [email protected]

Ioan Lie

Applied Electronics Department Fac. of Electronics and Telecom., “Politehnica” Un.

Timişoara, România

[email protected]

Abstract—In this paper is presented a new method how to decode

SPI signals. The signals are viewed and acquisitioned with an

oscilloscope, after that the signals is transferred to the PC through

Ethernet interface and decoded with the application using this

algorithm. SPI interface is quite commonly used for communication

between microchips, because it has a simple protocol. Testing this

communication can be done by decoding the SPI signals, which it’s

quite an elaborate task to do it manually, this way a simple

application which can do this can reduce a lot of time and effort.

Keywords-acquisition, decoding, Ethernet, interface, oscilloscope,

protocol, signal, SPI.

I. INTRODUCTION

This paper presents a new SPI decoding algorithm. SPI (Serial Peripheral Interface) bus is a synchronous serial data transmission. It was introduced by Motorola and it has full-duplex communication mode. Like other many communication protocols it has master/slave mode. The communication is made on 4 wires (Fig. 1); this way the algorithm is made on the 4 signals that are transferred from the oscilloscope to the PC. The 4 signals are named in a lot of ways, but the main idea is that we have a clock signal (CLK = Clock or SCLK = Serial Clock), two data signals (DI = Data In, DO = Data Out) and one enable

signal, chip select or slave select signal ( EN = Enable, CS =

Chip Select or SS = Slave Select), which shall select the slave

to which the master will communicate, because this protocol allows more slaves. As we can see the enable signal has inverted logic, so it activates the slave on 0.

Figure 1. SPI bus with Master and Slave

II. PROBLEM FORMULATION

We have a lot of development boards with microcontrollers, ASICs and other microchips. We wanted to test their functionality by sending and receiving commands on the SPI interface. The best way to test the SPI interface is to check the sent and received commands with oscilloscope and after decode them.

We have oscilloscopes with big sample rate, high precision and high frequency. Our oscilloscopes had Windows installed on them and some of them had touch screens too, they are made by Tektronix and LeCroy, some of the best companies in this area. These companies already provide signal decoding modules for these oscilloscopes, but they are very expensive and because of the lack of budget we couldn’t buy them, so we decided to make our own decoding application.

III. PROBLEM SOLUTION

A. Hardware Setup

We wanted to make simple application which can decode the SPI signals.

The basic idea is we have 2 LabVIEW programs which acquisition the SPI signals from the two oscilloscopes (Tektronix and LeCroy) and save all the 4 signals in 4 different Excel files which have as many rows as the sample rate (ex. 50 kS = 50000 rows in the Excel file). The signal samples are one under another in different rows. The acquisition is done on Ethernet interface.

The network was configured quite easily we used an internal IP address class that IANA (Internet Assigned Numbers Authority) provided.

PC: IP address: 192.168.10.1 Subnet mask: 255.255.255.0

Oscilloscope: IP address:192.168.10.2 Subnet mask: 255.255.255.0

This way if we connect the PC with the oscilloscope using the cable and maybe reconfigure or deactivate the firewalls on the two systems we shall have the PC and the oscilloscope on

CLK DI SPI

DO Slave

EN

CLK SPI DI

Master DO

EN

Legend: CLK=Clock DI=Data In DO=Data Out

EN =Enable

978-1-4673-1176-2/12/$31.00 ©2012 IEEE

Page 2: [IEEE 2012 10th International Symposium on Electronics and Telecommunications (ISETC) - Timisoara, Timis, Romania (2012.11.15-2012.11.16)] 2012 10th International Symposium on Electronics

the same subnet (192.168.10.X). After this in the oscilloscope software needs to be done some minor configurations like enable the TCP/IP communication. Finally we can say that with a correct application we can acquisition some signals from the oscilloscope.

The second application is the actual SPI decoding application made in LabWindows/CVI. We chose LabWindows/CVI, because it’s a text-based ANSI C programming language, where the loop in loop functions can be done more easily than in LabVIEW.

B. SPI Decoding Rule

Basically the decoding of these SPI signals means that we have the clock signal and according to this we look to the two data signals at the duration of the chip select (EN). The most common SPI signals can be on 8, 16 or 32 bits; this means that the clock signal can have 8, 16 or 32 transitions from 0 to 1. The signals are decoded during the clock signal. We compare first the DI and after the DO signal with the clock, when the clock has a transition we look first at one of the signals, if it has a transition too, than we have 1 otherwise 0. We continue like this until the clock signal lasts. After this we shall have an array with the length of the clock signal and with the content of 1 or 0 according to the data signal. This array after can be converted to Hexadecimal for easier interpretation. Some of the signals start with MSB (Most Significant Bit) others with LSB (Least Significant Bit), according to this we have to make sure that we did the Hexadecimal conversion right (from left to right or from right to left).

We can see on Fig. 2. the structure of 4 SPI signals (CLK,

DI, DO and EN ). We have the red lines on the rising edge of

the clock and the blue lines on the falling edge of the clock. Using the clock we can easily decode the signals. DI is 10111011 which mean 0xBB in Hexadecimal and DO is 11000010 which mean 0xC2 in Hexadecimal. As we could see the decoding method is quite simple, but this method needs to be adapted on our samples from the Excel files.

Figure 2. SPI signals: CLK, DI, DO and EN

C. SPI Signal Acquistion

The signal is acquisitioned with the oscilloscopes using LabVIEW application. The two kinds of oscilloscopes used are the Tektronix TDS5034B and the LeCroy WaveRunner 6050, but the application can work with any oscilloscope similar to the ones used.

On Fig. 3 we can see the print screen from the Tektronix oscilloscope with the SPI signals on 16 bits. The yellow and blue signals are the data signals (DI, DO) to be decoded, the

pink signal is the enable ( EN ) signal, and the green signal is

the clock (CLK) signal.

Figure 3. SPI signals on 16 bits on the Tektronix oscilloscope

On Fig. 4 we can see the print screen from the LeCroy oscilloscope with the SPI signals on 16 bits. The yellow and blue signals are the data signals (DI, DO) to be decoded, the

green signal is the enable ( EN ) signal, and the pink signal is

the clock (CLK) signal.

Figure 4. SPI signals on 16 bits on the LeCroy oscilloscope

On Fig. 5 we can see the print screen from the LeCroy oscilloscope with the SPI signals on 8 bits. The blue and green signals are the data signals (DI, DO) to be decoded, the pink

signal is the enable ( EN ) signal, and the yellow signal is the

clock (CLK) signal.

Figure 5. SPI signals on 8 bits on the LeCroy oscilloscope

CLK

DI

DO

EN

Page 3: [IEEE 2012 10th International Symposium on Electronics and Telecommunications (ISETC) - Timisoara, Timis, Romania (2012.11.15-2012.11.16)] 2012 10th International Symposium on Electronics

On Fig. 6 we can see the LabVIEW application which was made for the LeCroy oscilloscope. This application can acquisition signals and can transfer them to the PC on Ethernet interface. The 4 signals are also saved in 4 Excel files. The number of samples in the Excel files is equal with the sample rate set on our oscilloscopes (in our case 50 kS (Fig. 4 or Fig. 5) = 50000 samples in the Excel files).

Figure 6. The application made in LabVIEW which can acquisition the SPI

signals on16 bits with the LeCory oscilloscope and can transfer them to the PC on Ethernet interface

The application is quite easy to configure, the first control from the Front Panel is the most important, the VISA resource name, here we can configure the parameters of the interface, in our case the IP or GPIB address (for Tektronix oscilloscopes) and the IP address (for LeCroy oscilloscopes) in a specific format:

Tektronix: - TCPIP0::192.168.10.2:: inst0::INSTR - GPIB0::1::INSTR

LeCroy: - TCPIP0::192.168.10.2:: inst0::INSTR - VICP::192.168.10.2

For the Tektronix oscilloscope we can make the acquisition on GPIB interface too. In our case the 0 is the GPIB card number installed in on the PC and the 1 is the GPIB address configured from the oscilloscope.

For the LeCroy oscilloscope we can make acquisition on the Ethernet interface using the VICP protocol too, for this the lecroyvicppassportinstaller.exe application needs to be installed from the oscilloscope’s site.

Under the resource name we have time our configuration, where can be used default setting (10 s), under it we have to select the channels and under it we can move the signals vertically with the dials.

Near them we have the two graphs. On the first graph we can see similar signals with the ones from the oscilloscope, analog signals with noise. On the second graph we have the analog signals converted into digital signals. These digital signals are saved in the Excel files. In the Excel files we shall have only 1 or 0.

D. SPI Signal Decoding Application

On Fig. 7 and Fig. 8 we can see LabWindows/CVI application of the decoding of the SPI signals on 16 bits in

Binary, Hex (converting the Binary from left to right) and Inverted Hex (converting the Binary from right to left).

Figure 7. Decode SPI signals on 16 bits showing Hex (left to right) values

Figure 8. Decode SPI signals on 16 bits showing Inverted Hex (right to left)

values

On Fig. 9 and Fig. 10 we can see LabWindows/CVI application of the decoding of the SPI signals on 8 bits in Binary, Hex (converting the Binary from left to right) and Inverted Hex (converting the Binary from right to left).

Figure 9. Decode SPI signals on 8 bits showing Hex (left to right) values

Figure 10. Decode SPI signals on 8 bits showing Inverted Hex (right to left)

values

We can see that we have to configure the sample rate, which is 50000 in our case, because we had 50 kS on the oscilloscope and the clock if it’s on 8, 16 or 32 bits. Pressing the Decode SPI button we shall have two popup windows where we can select the signal file (DO, DI) and the clock (CLK) file for decoding.

Page 4: [IEEE 2012 10th International Symposium on Electronics and Telecommunications (ISETC) - Timisoara, Timis, Romania (2012.11.15-2012.11.16)] 2012 10th International Symposium on Electronics

On Fig. 11 we can see an Excel file with the pink signal on 16 bits from Fig. 6 (CLK) samples and the graph of the signal. The graph of the signal is shown on two Excel graphs, because Excel can represent only 32000 points and we have 50000 points.

Figure 11. The samples of the pink SPI clock signal on 16 bits in the Excel file

presented on graph

On Fig. 12 we can see an Excel file with the yellow signal on 16 bits from Fig. 6 (DI, DO) samples and the graph of the signal. The graph of the signal is shown on two Excel graphs, because Excel can represent only 32000 points and we have 50000 points.

Figure 12. The samples of the yellow SPI data signal on 16 bits in the Excel file

presented on graph

IV. CONCLUSION

We made a new SPI decoding algorithm, and we implemented it by creating two applications. The first application was made in LabVIEW to acquisition signals from the oscilloscope and to save the 4 SPI signal samples in different Excel files. The second application made in LabWindows/CVI decodes the SPI signals, by loading the Excel files previously saved by the LabVIEW application.

The algorithm is quite robust and it’s very simple, the problem is that the user needs a big display are more displays to have open all the two applications. In the other hand it’s made to be modular, because the decoding application shall work all the time if the Excel file meets the standards. This way if we need to acquisition the signals from another oscilloscope, or even a logic

analyzer we just have to create a new acquisition application (in LabVIEW or other programming language) and the decoding application shall decode our SPI signal.

In the future we would like to do further enhancements to the system by reducing the amount of work to the user and to create it on the oscilloscope directly or even embed it in the oscilloscope software and to write the decoding directly on the signals.

One easy method would be to translate the decoding algorithm in MATLAB programming language, because the LeCroy oscilloscopes with Windows have an embedded MATLAB module where some code can be executed if MATLAB is installed on the oscilloscope. The MATLAB code won’t write the decoding directly on the signals, but it will be written in the same window with the oscilloscope software write under the signals in a pop-up window.

REFERENCES

[1] R. Szabó, A. Gontean, I. Lie, M. BăbăiŃă, “Creating an Oscilloscope Driver,” International Conference on Applied Computer Science (ACS), 2010, pp. 220–225.

[2] R. Szabó, A. Gontean, I. Lie, M. BăbăiŃă, “Comparison between Agilent and National Instruments Functional Test Systems,” 8th International Symposium on Intelligent Systems and Informatics (SISY), 2010, pp. 87–92.

[3] A. Gontean, R. Szabó, I. Lie, “LabVIEW Powered Remote Lab,” 15th International Symposium for Design and Technology of Electronics Packages (SIITME), 2009, pp. 335–340.

[4] Jianlong Zhang, Chunyu Wu, Wenjing Zhang, Jiwei Wang, “The design and realization of a comprehensive SPI interface controller,” Second International Conference on Mechanic Automation and Control Engineering (MACE), 2011, pp. 4529–4532.

[5] A.K. Oudjida, M.L. Berrandjia, A. Liacha, A. Tiar, K. Tahraoui, Y.N. Alhoumays, “Design and test of general-purpose SPI Master/Slave IPs on OPB bus,” 7th International Multi-Conference on Systems Signals and Devices (SSD), 2010, pp. 1–6.

[6] Tianxiang Liu, Yunfeng Wang, “IP design of universal multiple devices SPI interface,” IEEE International Conference on Anti-Counterfeiting, Security and Identification (ASID), 2011, pp. 169–172.

[7] M. Turner, J. Naber, “The design of a bi-directional, RFID-based ASIC for interfacing with SPI bus peripherals,” 53rd IEEE International Midwest Symposium on Circuits and Systems (MWSCAS), 2010, pp. 554–557.

[8] Md M.K. Arshad, U. Hashim, Chew Ming Choo, “Characteristics of Serial Peripheral Interfaces (SPI) Timing Parameters for Optical Mouse Sensor,” International Conference on Semiconductor Electronics, (ICSE '06), 2006, pp. 576–582.

[9] A.K. Oudjida, M.L. Berrandjia, R. Tiar, A. Liacha, K. Tahraoui, “FPGA implementation of I2C & SPI protocols: A comparative study,” 16th IEEE International Conference on Electronics, Circuits, and Systems (ICECS), 2009, pp. 507–510.

[10] A. Flores-Abad, A. Arpidez, “Embedded Control System for a 5-DOF Manipulator by Means of SPI Bus,” Electronics, Robotics and Automotive Mechanics Conference (CERMA), 2009, pp. 151–156.

[11] An Shi-qi, Qi An-ning, Zhu Yu-wei, “Design and realization of SPI interface in lithiumion battery voltage measuring system,” 6th International Conference on Computer Science & Education (ICCSE), 2011, pp. 83–87.

[12] A. Szekacs, T. Szakall, Z. Hegykozi, “Realising the SPI communication in a multiprocessor system,” 5th International Symposium on Intelligent Systems and Informatics (SISY), 2007, pp. 213–216.