# Dedicated SPI pin numbers for PYNQ-Z1 IOP app

**URL:** <https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863>\
**Category:** Support\
**Created:** [October 8, 2020, 12:01am UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863 "2020-10-08T00:01:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![VicerExciser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/vicerexciser/32/1643_2.png) [@VicerExciser](https://discuss.pynq.io/u/VicerExciser)\
**Post date:** [October 8, 2020, 12:01am UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/1 "2020-10-08T00:01:04Z")

</div>

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:

```nohighlight
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:

```nohighlight
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](https://github.com/VicerExciser/VIP-KendedaNode/blob/master/vip/kendeda/air/pynq_node/opc/src/opc.c) and here is [the associated Python wrapper](https://github.com/VicerExciser/VIP-KendedaNode/blob/master/vip/kendeda/air/pynq_node/opc/opc.py) as well.

Any help will be most appreciated.

---

<div class="post-metadata">

**Author:** ![rock](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/rock/32/32_2.png) [@rock](https://discuss.pynq.io/u/rock)\
**Post date:** [October 15, 2020, 5:18pm UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/2 "2020-10-15T17:18:09Z")

</div>

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](https://github.com/Xilinx/PYNQ/blob/master/boards/sw_repo/pynqmb/src/spi.c#L64)).

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);

---

<div class="post-metadata">

**Author:** ![VicerExciser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/vicerexciser/32/1643_2.png) [@VicerExciser](https://discuss.pynq.io/u/VicerExciser)\
**Post date:** [October 15, 2020, 5:42pm UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/3 "2020-10-15T17:42:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rock](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/rock/32/32_2.png) [@rock](https://discuss.pynq.io/u/rock)\
**Post date:** [October 15, 2020, 7:22pm UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/4 "2020-10-15T19:22:27Z")

</div>

![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/4/45c62c26aa2610c999dc7bb64eb8005ab21a2dfc.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![magicarp\_xl](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/magicarp_xl/32/1746_2.png) [@magicarp\_xl](https://discuss.pynq.io/u/magicarp_xl)\
**Post date:** [January 27, 2021, 11:21pm UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/5 "2021-01-27T23:21:36Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/a/a0fe8b6441b0082ac1843bab699790ba2bb37af8.png)

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!

---

<div class="post-metadata">

**Author:** ![rock](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/rock/32/32_2.png) [@rock](https://discuss.pynq.io/u/rock)\
**Post date:** [January 28, 2021, 6:19pm UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/6 "2021-01-28T18:19:46Z")

</div>

I think you need to check [Arduino — Python productivity for Zynq (Pynq)](https://pynq.readthedocs.io/en/v2.6.1/pynq_libraries/arduino.html)  
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](https://github.com/Xilinx/PYNQ/blob/master/boards/sw_repo/pynqmb/src/spi.c#L64)  
remember that there are 2 SPI controllers, and the dedicated SPI pins are controlled by the 2nd SPI controller.

---

<div class="post-metadata">

**Author:** ![magicarp\_xl](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/magicarp_xl/32/1746_2.png) [@magicarp\_xl](https://discuss.pynq.io/u/magicarp_xl)\
**Post date:** [January 28, 2021, 10:04pm UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/7 "2021-01-28T22:04:28Z")

</div>

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`.

```nohighlight
#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.

---

<div class="post-metadata">

**Author:** ![rock](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/rock/32/32_2.png) [@rock](https://discuss.pynq.io/u/rock)\
**Post date:** [January 29, 2021, 6:21am UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/8 "2021-01-29T06:21:01Z")

</div>

Your understanding is correct, unless my understanding is also wrong 🙂

---

<div class="post-metadata">

**Author:** ![Bhargava\_Upadhya](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@Bhargava\_Upadhya](https://discuss.pynq.io/u/Bhargava_Upadhya)\
**Post date:** [October 19, 2023, 8:14pm UTC](https://discuss.pynq.io/t/dedicated-spi-pin-numbers-for-pynq-z1-iop-app/1863/9 "2023-10-19T20:14:33Z")

</div>

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
