# Arduino IOP SPI Configuration

**URL:** <https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097>\
**Category:** Support\
**Created:** [December 3, 2020, 5:04pm UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097 "2020-12-03T17:04:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![LM741](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/lm741/32/1572_2.png) [@LM741](https://discuss.pynq.io/u/LM741)\
**Post date:** [December 3, 2020, 5:04pm UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/1 "2020-12-03T17:04:51Z")

</div>

Hi guys,

In the pre-baked base overlay, the SPI frequency seems to be set a 6.25MHz (1/16 divider off the 100MHz CLK). In the python environment, can we manipulate the SPI frequency without having to reconfigure the base overlay with vivado? For example, I will need to generate a 50MHz SCLK for the SPI interface…

Thanks!

---

<div class="post-metadata">

**Author:** ![cathalmccabe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/cathalmccabe/32/3348_2.png) [@cathalmccabe](https://discuss.pynq.io/u/cathalmccabe)\
**Post date:** [December 7, 2020, 8:43am UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/2 "2020-12-07T08:43:27Z")

</div>

The available IP doesn’t support run time clock configuration, otherwise support for this would be included.  
The IP accepts an external clock that it then steps down internally. It may be possible to dynamically update the clock, but in the PYNQ base overlay, this clock is the main 100MHz clock used to clock most IP in the design, including the MicroBlaze processors. It probably isn’t a good idea to try and change this.

Cathal

---

<div class="post-metadata">

**Author:** ![LM741](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/lm741/32/1572_2.png) [@LM741](https://discuss.pynq.io/u/LM741)\
**Post date:** [December 9, 2020, 4:37pm UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/3 "2020-12-09T16:37:01Z")

</div>

From what I understand, the SPI controller is configured through a divider from the master clock (100MHz). It still would not be a good idea to change the divider ratio itself while keeping the master clock the same thus not impacting the microblaze timing?

---

<div class="post-metadata">

**Author:** ![LM741](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/lm741/32/1572_2.png) [@LM741](https://discuss.pynq.io/u/LM741)\
**Post date:** [December 9, 2020, 4:38pm UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/4 "2020-12-09T16:38:10Z")

</div>

The plan was to modify the clock divider setting in the AXI-SPI IP in the base overlay. I have not been able to test this since I have been running into a slew of problems trying to rebuild the base  
TCL in Vivado.

---

<div class="post-metadata">

**Author:** ![cathalmccabe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/cathalmccabe/32/3348_2.png) [@cathalmccabe](https://discuss.pynq.io/u/cathalmccabe)\
**Post date:** [December 10, 2020, 7:58am UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/5 "2020-12-10T07:58:15Z")

</div>

Yes, it would not be a good idea to modify the main clock. This may be a very quick way to check if you wanted to test your design at a slower clock speed.  
It would be much better to modify the clock divider.  
What problems are you having with rebuilding the design?

Cathal

---

<div class="post-metadata">

**Author:** ![LM741](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/lm741/32/1572_2.png) [@LM741](https://discuss.pynq.io/u/LM741)\
**Post date:** [December 11, 2020, 6:13pm UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/6 "2020-12-11T18:13:59Z")

</div>

I keep running into “can’t unset ‘period’: no such variable” error

EDIT: This was resolved by putting my glasses on and reading that Glasgow release (PYNQ 2.5) is designed for Vivado 2019.1 release which is what I am working with. Everything runs smoothly now.

---

<div class="post-metadata">

**Author:** ![reynaldogonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/reynaldogonzalez/32/1183_2.png) [@reynaldogonzalez](https://discuss.pynq.io/u/reynaldogonzalez)\
**Post date:** [April 25, 2021, 8:33am UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/7 "2021-04-25T08:33:03Z")

</div>

I was able to modify the clock divider and rebuild the base overlay.  
(I set the divider to 16 with a multiplier of 4, because I need a slower speed for my application)

Although, now I am having the problem of microblaze timing being impacted.  
When calling SPI transfer function, the SS is not idled low for enough time, i.e. the SS goes high again before all the clock cycles have finished.

What is the correct approach to edit/compile the spi.c code found in the sw\_repo folder?  
(Im assuming this is not done during the bitstream generation)  
Must I use the SDK to compile? If so, how do I get it to work on the Pynq-Z1 board?  
Are there any good examples to follow for this?

---

<div class="post-metadata">

**Author:** ![PeterOgden](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/peterogden/32/55_2.png) [@PeterOgden](https://discuss.pynq.io/u/PeterOgden)\
**Post date:** [April 26, 2021, 10:09am UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/8 "2021-04-26T10:09:39Z")

</div>

The easiest way is to edit the files in a copy of the PYNQ repository on a Linux machine with SDK and a reasonably current version of Anaconda installed and then run `python3 setup.py sdist` to create a new pynq-2.6.0.tar.gz which you can copy on to the board and then run `sudo pip3 install pynq-2.6.0.tar.gz` to install your new version on the board. After running sdist you can also copy the appropriate libxil.a files manually but I find it easy to get confused when doing that.

Peter

---

<div class="post-metadata">

**Author:** ![reynaldogonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/reynaldogonzalez/32/1183_2.png) [@reynaldogonzalez](https://discuss.pynq.io/u/reynaldogonzalez)\
**Post date:** [April 29, 2021, 6:25pm UTC](https://discuss.pynq.io/t/arduino-iop-spi-configuration/2097/9 "2021-04-29T18:25:38Z")

</div>

I was able to rebuild the board support package using the instructions on page 119 of [Pynq Documentation](https://pynq.readthedocs.io/_/downloads/en/latest/pdf/), (excluding step 4). I just have to make a copy of the repository folder every time I run make, because of some error saying the hw project exists already. I then just replace the bsp\_iop\_pmod folder with the one generated, renaming it to the same name, removing extra directories, and making all sub-files executable. This works for me since I am only making use of the pmod bsp.

Thanks,  
Rey
