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!

Showing results for 
Search instead for 
Did you mean: 
Observer jluisgt
Registered: ‎10-22-2014

Request for additional information for the SpiPs API.

Can anyone suggest a minimal working code to use the SpiPs API from Xilinx, operating in manual slave selection mode and manual start? We've been trying to read an encoder with the API said without satisfactory results.


A functional code for reading in Arduino is shown below, if it is of some help:


#include <SPI.h>
#define CS 10 //Chip or Slave select

uint16_t ABSposition = 0;
uint16_t ABSposition_last = 0;

int numPulsos = 4096;
float factor = 360/numPulsos; //0.087890625; //360/4096

unsigned int Pos=0;
float deg = 0.00;

uint8_t temp[2];

void setup()
  pinMode(CS,OUTPUT);//Slave Select

void loop()
   ABSposition = ReadEncoder();
   if(ABSposition != ABSposition_last)    //if nothing has changed dont wast time sending position
     ABSposition_last = ABSposition;    //set last position to current position
     //deg = ABSposition;
     //deg = deg * factor;    //
     Pos = ABSposition;
     Serial.println(Pos);     //send position in degrees

   delay(5);    //wait a bit till next check.

uint8_t  SPI_T(uint8_t msg)    //Repetive SPI transmit sequence
   uint8_t msg_temp = 0;  //vairable to hold received data
   digitalWrite(CS, LOW);     //select spi device
   msg_temp = SPI.transfer(msg);    //send and receive
   digitalWrite(CS,HIGH);    //deselect spi device
   return(msg_temp);      //return received byte

uint16_t ReadEncoder()
   uint8_t received = 0xA5;    //just a temp variable
   ABSposition = 0;    //reset position variable
   SPI.begin();    //Start transmission.
   digitalWrite(CS,LOW); //Habilitar disp SPI.
   SPI_T(0x10);   //issue read command
   received = SPI_T(0x00);    //issue NOP to check if encoder is ready to send
   while (received != 0x10)    //loop while encoder is not ready to send
     received = SPI_T(0x00);    //check again if encoder is still working 
     delay(1);    //wait a bit  --Cambiado de 2 a 1, probando.
   temp[0] = SPI_T(0x00);    //Receive MSB
   temp[1] = SPI_T(0x00);    //Receive LSB

   digitalWrite(CS, HIGH);  //just to make sure   
   SPI.end();    //end transmition
   temp[0] &=~ 0xF0;    //mask out the first 4 bits, 00001111
   ABSposition = temp[0] << 8;    //shift MSB to correct ABSposition in ABSposition message
   ABSposition += temp[1];    // add LSB to ABSposition message to complete message

  return ABSposition;

Currently in our code the API is set only by activating the master mode flag (XSPIPS_MASTER_OPTION) and a reduction clock factor of 64 (XSPIPS_CLK_PRESCALE_64). If we activate the manual slave selection flag no data is retrieved from the encoder; if we deactivate the flag data is retrieved but are invalid . All examples in Xilinx activate the manual slave selection flag (XSPIPS_FORCE_SSELECT_OPTION) so we kindly request information about why the flag must be activated.


As can be seen in the Arduino code one byte is recovered every time, not data bursts. Any suggested configuration of the Xilinx APIfor this type of application?


We have been trying for days with different combinations of configuration flags without favorable results, so I turn to the experts for some guidance. Thanks in advance.

0 Kudos
3 Replies
Visitor walterdf00
Registered: ‎10-02-2014

Re: Request for additional information for the SpiPs API.

If you have the SDK installed you can browse to this path in your install and get some really good examples and sources:



I think all the examples are geared toward a stand-alone or bare-metal application rather than an OS implementation, though.

0 Kudos
Observer jluisgt
Registered: ‎10-22-2014

Re: Request for additional information for the SpiPs API.



I have read the suggested examples, both to read the EEPROM and the flash memory (although they are for the version two of the SPI PS API, not the new third version), as well as chapter 17 of the user guide 585, concerning the SPI API. I still have a question, how the reference to the  desired slave is made? 0 to 2, 1 to 3, or 1,2,4? I have tried with 0 and 1 to access the first slave without favorable results. Do you recommend installing the new version of Vivado and SDK to try with the newer version of the SPI API?

0 Kudos
Observer jluisgt
Registered: ‎10-22-2014

Re: Request for additional information for the SpiPs API.

Vivado updated to 2015.4 version in order to try the new SPI v3 but apparently the project still pointing to the v2 of the SPI library. Any suggestion?

0 Kudos