Dedicated SPI pin numbers for PYNQ-Z1 IOP app

Hello. I’m currently writing an application for the Arduino IOP on the PYNQ-Z1 to communicate with a sensor via SPI. I have the sensor connected to the SPI header and am using the Xilinx-provided SPI library (boards/sw_repo/pynqmb/src/spi.h); however, I cannot find any mention in the docs or examples of what pin numbers are associated with the dedicated SPI pins to be passed as args to the spi_open() function.

Right now, I’m using the following pin assignments:

const unsigned int SPICLK_PIN = 13;
const unsigned int MISO_PIN = 12;
const unsigned int MOSI_PIN = 11;
const unsigned int SS_PIN = 10;

And I’m invoking spi_open like so:

spi_device = spi_open(SPICLK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);

I’m thus far unable to communicate with the sensor, and the MicroBlaze program seems to consistently hang on the first attempted SPI transfer. For reference, here is my IOP program source and here is the associated Python wrapper as well.

Any help will be most appreciated.

1 Like

You need to first find out which spi controller you want to use. If it is not SPI controller 0, you will have to use spi_open_device() instead (PYNQ/spi.c at master · Xilinx/PYNQ · GitHub).

Then after open device, you can set up pins.

set_pin(spiclk, SPICLK0);
set_pin(miso, MISO0);
set_pin(mosi, MOSI0);
set_pin(ss, SS0);

Am I using the correct pin numbers for the dedicated SPI header though?

Pins are correct, but it might be on the other SPI controller. There are 2 SPI controllers, one connected to the dedicated header pin, the other connected to pin 10-13.

Hello, I’m having the same question as OP. The PYNQ-Z1 board’s documentation only shows the following diagram.

I’d like to use the two SPI controllers at the same time, but where can I find the correspondence of the int number of the pins and their names? Is the picture you posted here from a public documentation? Can you share it?

Thanks!

I think you need to check Arduino — Python productivity for Zynq (Pynq)
but since you are using the dedicated SPI, it may be that you don’t need to provide the pin number. Use PYNQ/spi.c at master · Xilinx/PYNQ · GitHub
remember that there are 2 SPI controllers, and the dedicated SPI pins are controlled by the 2nd SPI controller.

Hey rock, thanks for the reply!
So my understanding is shown in the code below. I’m using the base.bit and the code would go into the MB processor in base.ARDUINO.

#include "spi.h"

static spi device0, device1;

device0 = spi_open(13, 12, 11, 10)  //this uses SPI0 and pins D13~D10
device0 = spi_configure(device0, 1, 1)

device1 = spi_open_device(1) //this uses SPI1 and the dedicated pins
device1 = spi_configure(device1, 1, 1)

// spi_transfer stuff

I haven’t got the chance to test the code yet. But would assume this is what you mean. Otherwise I just don’t know how to refer to these PINs when writing C code for the MB processor.

Your understanding is correct, unless my understanding is also wrong :slight_smile:

Hi @rockstiff ,

Could you please let me know if it’s also possible to use the other Arduino pins (0-10) as slave select? I am trying to connect multiple slaves for my requirement.

Regards,
Bhargava