SPI Block

124 views
Skip to first unread message

KT Chiam

unread,
May 21, 2024, 11:57:45 AMMay 21
to FPGAwars: explorando el lado libre
Hi. I'm trying to use SPI in my application. For now, I just try to write a byte to SPI MOSI and check the output at oscilloscope. The output is not what I expect (see attached scope capture. yellow is SCLK, magenta is MOSI. there are too many clocks for SCLK? Can someone guide me how to use the SPI block? 

Thank you
spi.ice
DSO00001.jpg

charli va

unread,
May 21, 2024, 12:38:13 PMMay 21
to fpga-wars-explora...@googlegroups.com
Hi KT, here you have an excellent documentation by Obijuan (in spanish but i think you could translate easy with chatgpt or similar):


I hope should be useful for you!


El mar, 21 may 2024 a las 17:57, KT Chiam (<kokthia...@gmail.com>) escribió:
Hi. I'm trying to use SPI in my application. For now, I just try to write a byte to SPI MOSI and check the output at oscilloscope. The output is not what I expect (see attached scope capture. yellow is SCLK, magenta is MOSI. there are too many clocks for SCLK? Can someone guide me how to use the SPI block? 

Thank you

--
Has recibido este mensaje porque estás suscrito al grupo "FPGAwars: explorando el lado libre" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a fpga-wars-explorando-el...@googlegroups.com.
Para ver esta conversación en el sitio web, visita https://groups.google.com/d/msgid/fpga-wars-explorando-el-lado-libre/1b546a16-4391-4f6b-8435-82e95f16a385n%40googlegroups.com.

Democrito

unread,
May 21, 2024, 1:40:18 PMMay 21
to FPGAwars: explorando el lado libre
Hi KT,

The problem is that you are sending a square wave to the "start" pin. That pin operates with one tick (a single clock cycle). There is a module that produces a tick for each rising edge of a square wave.

I attach your corrected circuit, you will see the module that I mentioned and that you can see in this image.

spi start.png

In this way, for each rising edge of the square wave it will generate a single clock cycle (tick).

If you load the circuit I attached, you have two options.

1.) I don't have your board, so you have to select it (Select -> Board -> ICE40-HX8K...)  And then you have to redefine the pinout you chose (for the LEDs, SCK, MOSI, etc).

2.) When you open the circuit attached, click on "Convert" and copy the module (click on the module and then "control C") that I have indicated in yellow in the image above. And then you insert it into your circuit (control V) and connect it as shown in the image.

Make sure Icestudio is configured to work with your board; This is important and you can see it in the bottom right corner.

If you have any problems with this, let me know and I'll try to be more graphic.

I have tested the circuit I attached and it works perfectly.

Greetings.
spi_test_AA.ice

Democrito

unread,
May 21, 2024, 1:58:30 PMMay 21
to FPGAwars: explorando el lado libre
I leave you a test image in which you can see that it works perfectly.

pulseView SPI  send AA.png

Most of the time, whether you design with Icestudio or directly in Verilog, internally it needs a single clock cycle, to compare, count, give the start signal, etc.

charli va

unread,
May 21, 2024, 6:50:44 PMMay 21
to fpga-wars-explora...@googlegroups.com
Thanks Democrito !

--
Has recibido este mensaje porque estás suscrito al grupo "FPGAwars: explorando el lado libre" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a fpga-wars-explorando-el...@googlegroups.com.

Democrito

unread,
May 21, 2024, 7:45:00 PMMay 21
to FPGAwars: explorando el lado libre
Thank you Carlos for this program and that it has given me so much life and has allowed me to meet such interesting people!

Now let's see if KT can get its circuit working. Any problems or questions you have KT, please don't hesitate to comment.

KT Chiam

unread,
May 21, 2024, 8:12:22 PMMay 21
to FPGAwars: explorando el lado libre
Hi All,

Thank you very much and appreciate help from all of you. The circuit is working perfectly after the correction. 

By the way, I try to dig further into the blocks. How can I copy the comments for translation?
comment.png

Democrito

unread,
May 22, 2024, 12:27:32 AMMay 22
to FPGAwars: explorando el lado libre
I don't know if there is any method to translate directly from Icestudio, I think there is (from English to other languages) but I have never tried it.

I hope another user can answer this question for you.

Anyway, I'll show you how to copy and modify any text you find.

If you are on the main page of the circuit, all you have to do is double click on the text.

And if you are inside a module, you must first open the lock to be able to do what I mentioned above. In this animated image you can see exactly what I'm talking about.

capture text.gif

In this other animated GIF I show you how to create and modify an informative text. In this case I manually translate the text.

comment this is a NAND gate.gif

Inside the info box I do "Control A" (select all) and then "Control C". I paste it into a translator and when they translate it for me I copy it. Going back to the code box I select everything and do "Control V" (paste).

On the other hand, notice that when you double-click on the text, the information box appears, as explained above. And if you double click on any corner or side of the info box, only the text appears and the info box disappears.

When inside an infobox, you can use Markdown notation.

Democrito

unread,
May 22, 2024, 12:45:01 AMMay 22
to FPGAwars: explorando el lado libre
In the previous post, if you read "code box" I meant "information box"

KT Chiam

unread,
May 22, 2024, 1:11:57 AMMay 22
to FPGAwars: explorando el lado libre
Hi,

Just want to share that I have found it. Just click the lock icon and it will unlock. Thank you.

Jesus Arias

unread,
May 22, 2024, 3:27:50 AMMay 22
to FPGAwars: explorando el lado libre
Hi,
Looking at your capture I can see the clock edges are the opposite of what is usually expected:
- Bits changing on falling edges
- Bits sampled on rising edges
So, I think the SCK signal should be inverted before attaching it to an external device, just in case...
Regards

pulseView SPI send AA.png

KT Chiam

unread,
Jun 24, 2024, 12:19:59 AM (9 days ago) Jun 24
to FPGAwars: explorando el lado libre
Hi Charliva,

Thank you, the guide is excellent. 
I tried to download and open some of the examples, but it will result in error. Is it newer version can't open older version code? I have trouble to find the icons based on the guide. Thank you.

charli va

unread,
Jun 24, 2024, 10:36:27 AM (9 days ago) Jun 24
to fpga-wars-explora...@googlegroups.com
Hi KT! what are the links that not working? this is an Obijuan's repository and i don't know if are up to date but i think  Obijuan has been  updating all of his repositories and documentation to the new version of toolchains.

Be careful if you are using some automatic translator, because some times could be change links.

If you have  doubts tell us and we try to help you.

Have a nice day!

KT Chiam

unread,
Jun 24, 2024, 11:14:54 AM (9 days ago) Jun 24
to FPGAwars: explorando el lado libre
Hi Chatty, 

It seems to be working now. May be there was an error when I downloaded previously.

I could not find the code blocks from the Jedi-master collection. For example, see attached capture. Is it just copy the block and paste into my own code?
Code blocks.png

Also, what is the difference between Input / Output Label vs Paired Labels?
Labels.png
03-spi-master-lectura-escritura.ice

Democrito

unread,
Jun 24, 2024, 2:38:12 PM (9 days ago) Jun 24
to FPGAwars: explorando el lado libre
Hi KT,

1.) "It seems to be working now. May be there was an error when I downloaded previously."

- It could be what you say and it could also be that Icestudio is not loading the circuit. When this last case happens, try it several times.

2.) "I could not find the code blocks from the Jedi-master collection. For example, see attached capture. Is it just copy the block and paste into my own code?"
Yes, 


- Yes, you can copy and paste the block or blocks, whether from a collection or another circuit. It is very common to do so.

3.) "Also, what is the difference between Input / Output Label vs Paired Labels?"

- There can be pairs of labels (for each input one output) to facilitate connections because it is very common for them to be two by two, and they can also be individual because, for example, an input label can go (for example) to several of exit.

Greetings.

Democrito

unread,
Jun 24, 2024, 2:44:06 PM (9 days ago) Jun 24
to FPGAwars: explorando el lado libre
The labels replace connecting wires and are used to make the circuit look "cleaner." An input tag is linked to an output tag or to multiple output tags as long as they have the same name.
Reply all
Reply to author
Forward
0 new messages