UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Adam Taylor’s MicroZed(ish) Chronicles Part 82: Simple Communication Interfaces Part 2

by Xilinx Employee on ‎05-18-2015 09:53 AM (49,811 Views)

 

By Adam Taylor

 

Following on from last week’s blog we’re heading towards programming an OLED display for the Zedboard (not the MicroZed). Before we jump too far into programming the OLED however, I thought it would be a good idea to ensure that we have correctly configured the SPI port for the application. This could save us lots of time later on and it’s very simple to do. In fact it is so simple, I am going to demonstrate two different methods in this single blog post. The first method will route the SPI pins out via the Zynq SoC’s MIO while the second will route the SPI pins out via the EMIO. What’s the difference? Keep reading.

 

I am going to cheat a little. I will route SPI0 out over the Zynq SoC’s EMIO and SPI1 out over the MIO. This can be done very easily within Vivado. First, enable SPI1 and route it to MIO pins 10 to 15. These pins are connected to the PS MOD (JE) on the Zedboard. SPI0 is going to be routed to PMOD JC and requires you to select EMIO from the drop down menu. We can then use IO placement constraints to route the EMIO pins to drive the JC PMOD. However if you read the Zynq TRM—and you always should—you will discover that if you use the EMIO, you will need to tie SPIx_SSI high. I’ve used a constant, as shown below:

 

 

 Image4.jpg

 

 

We now have two SPI controllers we can use to drive data out to PMOD ports. We drive these using software that’s identical to what we’ve used before and as we go through the following stages, the code should be very familiar. (We are 82 blogs in, it better be.)

 

The code must:

 

  • Include the relevant header file for the API support in this case xspips.h
  • Define the SPI device IDs
  • Declare global instances of the correct SPI type – XspiPs

 

Within the function that configures and uses the SPI devices, the code must:

 

  • Declare configuration instances using typ – XspiPs_Config
  • Look up the configuration using SpiConfig = XSpiPs_LookupConfig((u16)SPI_DEVICE_ID);
  • Initialize the configuration using XSpiPs_CfgInitialize(&SpiInstance, SpiConfig, SpiConfig->BaseAddress);

 

With the basic SPI devices initialized and configured, we can begin to configure the operation of the SPI controllers for our application as we desire. The first thing we want to do is set the options using

 

 

XSpiPs_SetOptions()

 

 

Using this function we can set the master or slave mode, set clock active and phase options, choose how we perform slave selection, and configure how the master starts.

 

We also need to be able to set the prescaler to set the clock at the correct frequency for the slave. We can do this using:

 

 

XSpiPs_SetClkPrescaler()

 

 

If you remember from last week we needed a prescaler of at least 64 to meet the timing for the OLED. In this example, the test outputs will only drive an oscilloscope so for the purposes of this blog, I selected 256, the largest prescaler divisor.

 

We can now send data to our slave in the simplest fashion using either an interrupt-driven or a polled transfer. I used the polled approach in this example, because it’s the simplest approach and therefore the easiest to understand.

 

I have uploaded the code that I created to the Github repository, but here are the results from a PicoScope attached to the MIO and EMIO outputs:

 

 

Image1.jpg 

 

 

PMOD JC SPI data Clock and Data (top) EMIO

 

 

 

Image2.jpg

 

PMOD JE SPI Clock and Data (Top) MIO

 

 

As you can see, both of these captures are identical. Data changes state on the falling edge of the clock and is thus stable for sampling on the rising edge of the clock as the OLED interface requires.

 

 

Image3.jpg

 

 

Now we are sure we have the SPI configured correctly we can progress on with the development. Whenever possible, it is always worth validating each development step to reduce risks as we progress. This example also shows how we can use the EMIO pins. We will need the EMIO for the OLED project and may again use the EMIO in future developments.

 

You can obtain the demo file here.

 

 

 

 

 MicroZed Chronicles.jpg

 

 

 

 

 

Now, you can have convenient, low-cost Kindle access to the first year of Adam Taylor’s MicroZed Chronicles for a mere $7.50. Click here.

 

 

Please see the previous entries in this MicroZed Chronicles series by Adam Taylor:

 

Adam Taylor’s MicroZed(ish) Chronicles Part 81: Simple Communication Interfaces

 

Adam Taylor’s MicroZed Chronicles Part 80: LWIP Stack Configuration

 

Adam Taylor’s MicroZed Chronicles Chronicles Part 79: Zynq SoC Ethernet Part III

 

Adam Taylor’s MicroZed Chronicles Chronicles Part 78: Zynq SoC Ethernet Part II

 

Adam Taylor’s MicroZed Chronicles Microzed Chronicles Part 77 – Introducing the Zynq SoC’s Ethernet

 

Adam Taylor’s MicroZed Chronicles Part 76: Constraints for Relatively Placed Macros

 

Adam Taylor’s MicroZed Chronicles, Part 75: Placement Constraints – Pblocks

 

Adam Taylor’s MicroZed Chronicles, Part 73: Physical Constraints

 

Adam Taylor’s MicroZed Chronicles, Part 73: Working with other Zynq-Based Boards

 

Adam Taylor’s MicroZed Chronicles, Part 72: Multi-cycle Constraints

 

Adam Taylor’s MicroZed Chronicles, Part 70: Constraints—Clock Relationships and Avoiding Metastability

 

Adam Taylor’s MicroZed Chronicles, Part 70: Constraints—Introduction to timing and defining a clock

 

Adam Taylor’s MicroZed Chronicles Part 69: Zynq SoC Constraints Overview

 

Adam Taylor’s MicroZed Chronicles Part 68: AXI DMA Part 3, the Software

 

Adam Taylor’s MicroZed Chronicles Part 67: AXI DMA II

 

Adam Taylor’s MicroZed Chronicles Part 66: AXI DMA

 

Adam Taylor’s MicroZed Chronicles Part 65: Profiling Zynq Applications II

 

Adam Taylor’s MicroZed Chronicles Part 64: Profiling Zynq Applications

 

Adam Taylor’s MicroZed Chronicles Part 63: Debugging Zynq Applications

 

Adam Taylor’s MicroZed Chronicles Part 62: Answers to a question on the Zynq XADC

 

Adam Taylor’s MicroZed Chronicles Part 61: PicoBlaze Part Six

 

Adam Taylor’s MicroZed Chronicles Part 60: The Zynq and the PicoBlaze Part 5—controlling a CCD

 

Adam Taylor’s MicroZed Chronicles Part 59: The Zynq and the PicoBlaze Part 4

 

Adam Taylor’s MicroZed Chronicles Part 58: The Zynq and the PicoBlaze Part 3

 

Adam Taylor’s MicroZed Chronicles Part 57: The Zynq and the PicoBlaze Part Two

 

Adam Taylor’s MicroZed Chronicles Part 56: The Zynq and the PicoBlaze

 

Adam Taylor’s MicroZed Chronicles Part 55: Linux on the Zynq SoC

 

Adam Taylor’s MicroZed Chronicles Part 54: Peta Linux SDK for the Zynq SoC

 

Adam Taylor’s MicroZed Chronicles Part 53: Linux and SMP

 

Adam Taylor’s MicroZed Chronicles Part 52: One year and 151,000 views later. Big, Big Bonus PDF!

 

Adam Taylor’s MicroZed Chronicles Part 51: Interrupts and AMP

 

Adam Taylor’s MicroZed Chronicles Part 50: AMP and the Zynq SoC’s OCM (On-Chip Memory)

 

Adam Taylor’s MicroZed Chronicles Part 49: Using the Zynq SoC’s On-Chip Memory for AMP Communications

 

Adam Taylor’s MicroZed Chronicles Part 48: Bare-Metal AMP (Asymmetric Multiprocessing)

 

Adam Taylor’s MicroZed Chronicles Part 47: AMP—Asymmetric Multiprocessing on the Zynq SoC

 

Adam Taylor’s MicroZed Chronicles Part 46: Using both of the Zynq SoC’s ARM Cortex-A9 Cores

 

Adam Taylor’s MicroZed Chronicles Part 44: MicroZed Operating Systems—FreeRTOS

 

Adam Taylor’s MicroZed Chronicles Part 43: XADC Alarms and Interrupts 

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 42: MicroZed Operating Systems Part 4

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 41: MicroZed Operating Systems Part 3

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 40: MicroZed Operating Systems Part Two

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 39: MicroZed Operating Systems Part One

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 38 – Answering a question on Interrupts

 

Adam Taylor’s MicroZed Chronicles Part 37: Driving Adafruit RGB NeoPixel LED arrays with MicroZed Part 8

 

Adam Taylor’s MicroZed Chronicles Part 36: Driving Adafruit RGB NeoPixel LED arrays with MicroZed Part 7

 

Adam Taylor’s MicroZed Chronicles Part 35: Driving Adafruit RGB NeoPixel LED arrays with MicroZed Part 6

 

Adam Taylor’s MicroZed Chronicles Part 34: Driving Adafruit RGB NeoPixel LED arrays with MicroZed Part 5

 

Adam Taylor’s MicroZed Chronicles Part 33: Driving Adafruit RGB NeoPixel LED arrays with the Zynq SoC

 

Adam Taylor’s MicroZed Chronicles Part 32: Driving Adafruit RGB NeoPixel LED arrays

 

Adam Taylor’s MicroZed Chronicles Part 31: Systems of Modules, Driving RGB NeoPixel LED arrays

 

 Adam Taylor’s MicroZed Chronicles Part 30: The MicroZed I/O Carrier Card

 

Zynq DMA Part Two – Adam Taylor’s MicroZed Chronicles Part 29

 

The Zynq PS/PL, Part Eight: Zynq DMA – Adam Taylor’s MicroZed Chronicles Part 28  

 

The Zynq PS/PL, Part Seven: Adam Taylor’s MicroZed Chronicles Part 27

 

The Zynq PS/PL, Part Six: Adam Taylor’s MicroZed Chronicles Part 26

 

The Zynq PS/PL, Part Five: Adam Taylor’s MicroZed Chronicles Part 25

 

The Zynq PS/PL, Part Four: Adam Taylor’s MicroZed Chronicles Part 24

 

The Zynq PS/PL, Part Three: Adam Taylor’s MicroZed Chronicles Part 23

 

The Zynq PS/PL, Part Two: Adam Taylor’s MicroZed Chronicles Part 22

 

The Zynq PS/PL, Part One: Adam Taylor’s MicroZed Chronicles Part 21

 

Introduction to the Zynq Triple Timer Counter Part Four: Adam Taylor’s MicroZed Chronicles Part 20

 

Introduction to the Zynq Triple Timer Counter Part Three: Adam Taylor’s MicroZed Chronicles Part 19

 

Introduction to the Zynq Triple Timer Counter Part Two: Adam Taylor’s MicroZed Chronicles Part 18

 

Introduction to the Zynq Triple Timer Counter Part One: Adam Taylor’s MicroZed Chronicles Part 17

 

The Zynq SoC’s Private Watchdog: Adam Taylor’s MicroZed Chronicles Part 16

 

Implementing the Zynq SoC’s Private Timer: Adam Taylor’s MicroZed Chronicles Part 15

 

MicroZed Timers, Clocks and Watchdogs: Adam Taylor’s MicroZed Chronicles Part 14

 

More About MicroZed Interrupts: Adam Taylor’s MicroZed Chronicles Part 13

 

MicroZed Interrupts: Adam Taylor’s MicroZed Chronicles Part 12

 

Using the MicroZed Button for Input: Adam Taylor’s MicroZed Chronicles Part 11

 

Driving the Zynq SoC's GPIO: Adam Taylor’s MicroZed Chronicles Part 10

 

Meet the Zynq MIO: Adam Taylor’s MicroZed Chronicles Part 9

 

MicroZed XADC Software: Adam Taylor’s MicroZed Chronicles Part 8

 

Getting the XADC Running on the MicroZed: Adam Taylor’s MicroZed Chronicles Part 7

 

A Boot Loader for MicroZed. Adam Taylor’s MicroZed Chronicles, Part 6 

 

Figuring out the MicroZed Boot Loader – Adam Taylor’s MicroZed Chronicles, Part 5

 

Running your programs on the MicroZed – Adam Taylor’s MicroZed Chronicles, Part 4

 

Zynq and MicroZed say “Hello World”-- Adam Taylor’s MicroZed Chronicles, Part 3

 

Adam Taylor’s MicroZed Chronicles: Setting the SW Scene

 

Bringing up the Avnet MicroZed with Vivado

 

Comments
by Visitor kurtcopley
on ‎07-10-2015 07:11 AM

A tip to get the SS to stay high after the SPI transaction:

 

I found that the MIO SPI1 will need to enable the pull up on the SS as well.

 

I would have expected this need if the SPI were used in a multi-master mode but it wasn't (At least I didn't intend it to be). The SDK's BSP will need to be manually recreated as well, even if the dialog leads you to think it did so automatically. I right mouse clicked on the standalone_bsp project and selected "Re-generate BSP Sources" to get the pull up to be fully enabled.

 

The 2015.1 SPI library actually enables/disables the peripheral during XSpiPs_PolledTransfer() function in support of a multi-master system. I believe this to be the source of the the problem of the SS not being driven high and requiring the pull up to be enabled.

by Voyager
on ‎07-13-2015 05:51 PM

This list is a great index to Taylor's articles.  I see the Permalink which suggest it will remain.  You might want to link these articles to a QuickLink on the Blog home page.  Makes them easier to find and it should be easier to update as new articles are added.

by Xilinx Employee
on ‎07-15-2015 12:10 PM

You can find a running list of links to all of Adam Taylor's MicroZed Chronicles at:

 

http://adiuvoengineering.com/?page_id=285

 

--Steve

 

by Newbie fcgozcu
on ‎09-25-2015 02:57 PM

Hi Everyone,

 

I am newbie about embedded systems and ZYNQ. I am trying to implement the code which is very similar one used in this example but sometimes I stuck in the XSpiPs_PolledTransfer(). I try to change the number of bytes that written in polled transfer function but nothing is changed.

 

When I debug the code I saw that code stuck in this part of xspips.c :

 

"while (CheckTransfer == 0U){
            StatusReg = XSpiPs_ReadReg(
                            InstancePtr->Config.BaseAddress,
                                XSPIPS_SR_OFFSET);
                if ( (StatusReg & XSPIPS_IXR_MODF_MASK) != 0U)"

 

 

And this is my code. It is just for verifying the ss pin.  Any help will be appreciated greatly!

 

 

 

 

 

#include <stdio.h>
#include "platform.h"
#include "xspips.h"
#include "xparameters.h"


#define test_op 0xFF



static XSpiPs spiInstance;



int main()
{


    XSpiPs_Config  *spiInstance_Config;
    int status;
    u8 write_buffer[1];


    init_platform();



    printf("Hello World\n\r");

    spiInstance_Config = XSpiPs_LookupConfig(XPAR_PS7_SPI_0_DEVICE_ID);
    status = XSpiPs_CfgInitialize(&spiInstance, spiInstance_Config, spiInstance_Config->BaseAddress);
    if (status != XST_SUCCESS)
        return XST_FAILURE;


    XSpiPs_SetOptions(&spiInstance, XSPIPS_MASTER_OPTION|
    XSPIPS_CLK_ACTIVE_LOW_OPTION | XSPIPS_FORCE_SSELECT_OPTION);        //dac8560 is clocked data to falling edge of sclk
                                                                    //cs is done by software command and master mode selected


    XSpiPs_SetClkPrescaler(&spiInstance, XSPIPS_CLK_PRESCALE_64);


    memset(write_buffer, 0x00, sizeof(write_buffer));
    write_buffer[0] = (u8) 0xFF;


    XSpiPs_SetSlaveSelect(&spiInstance, 0x01);
    printf ("..\n\r");
    XSpiPs_SetSlaveSelect(&spiInstance, 0x00);
    XSpiPs_PolledTransfer(&spiInstance, write_buffer ,NULL, 1);
    XSpiPs_SetSlaveSelect(&spiInstance, 0x01);
    printf ("Dac is configured to give 1.25V\n\r");

    while(1);

    cleanup_platform();
    return 0;

 

 

 

 

 

 

 

 

Labels
About the Author
  • Be sure to join the Xilinx LinkedIn group to get an update for every new Xcell Daily post! ******************** Steve Leibson is the Director of Strategic Marketing and Business Planning at Xilinx. He started as a system design engineer at HP in the early days of desktop computing, then switched to EDA at Cadnetix, and subsequently became a technical editor for EDN Magazine. He's served as Editor in Chief of EDN Magazine, Embedded Developers Journal, and Microprocessor Report. He has extensive experience in computing, microprocessors, microcontrollers, embedded systems design, design IP, EDA, and programmable logic.