Interpreting SPI Commands in FPGA Applications

  • Thread starter Thread starter unplebeian
  • Start date Start date
Click For Summary
FPGA execution of SPI commands involves capturing data through the MOSI line, which is clocked into a shift register upon receiving a chip select signal. The FPGA then interprets this data based on the loaded configuration, which dictates subsequent actions such as modifying register values or initiating processes. The behavior following data reception is application-specific, as the FPGA's function depends on its intended use, such as interfacing with sensors or controlling devices. Understanding the SPI protocol is crucial, but the implementation and next steps are determined by the specific application requirements. Ultimately, the FPGA's versatility allows it to adapt to various communication tasks, making it a powerful tool in embedded systems.
unplebeian
Messages
157
Reaction score
1
TL;DR
How does an I2C/SPI command write to an FPGA gets executed?
Hi folks,

Can someone explain to me how an FPGA executes an I2C/SPI/other command written to it. I understand that there is an I2C_RX or a SPI_RX module that acts as a slave and can get the transmitted data. But shouldn't there be another interpreter that deciphers the data and takes action on it such as change the contents of another register etc.

How is this interpretation done/written in FPGA? Can someone give me an example.

Thanks.
 
Engineering news on Phys.org
I'll talk about SPI because I think it's more slightly more simple compared to I2C.

The most straightforward SPI has four wires: master out slave in (MOSI), master in slave out (MISO), chip select or slave select (CS or SS), and a clock (CLK). It can have multiple CS for multiple slave devices; I've also seen some variants of it including a latch data.

Chip select (CS) triggers first telling the chip that it's going to receive something. The data from master device comes into the slave device (MOSI) and the slave device echos what it is receiving (MISO). This is just a bunch of high or low voltages (1's or 0's), and it's loaded or clocked into a shift register. Once the shift register is full it has a bunch of 1's and 0's that can be used in later digital logic (NOT, NOR, NAND's, flip-flip, etc.) or can even go into a processor.

The HDL if you were looking at something like Verilog would make the always statement sensitive to the clock- do something when the clock is a positive or negative edge, or both. The first condition would be an if statement (equivalent to a multiplexer MUX) that would check if the chip select is satisfied. If the chip select is satisfied, then load the input value (MOSI) into registers for so many clock cycles; echo whatever is loaded into to the registers to the output (MISO). When it's all done you have a loaded register that you can use for logic.

I was going to write a SPI in verilog, but I see there are lots of examples found through a search engine. As for the FPGA itself a lot of the products I've seen you can write a SPI with C programming and a SPI command might be as simple one or two liner like transfer(data) or writeRead(data). MATLAB has some examples (here's where I looked).
 
  • Like
Likes berkeman
Hi Joshy,

I understand the protocol itself but I am still uncertain about what the next step is. I understand that the FPGA can capture the MOSI data on the clock edge (depending on the SPI mode). Let me give you an example.

Let's say we want to write the data from reg 0x5 using the SPI protocol. The FPGA receives a SPI command to do just that and stores the MISO data in some reg. But what happens next. How do we distinguish what to do next based on the MISO command - to either change a reg value or start execution of some other process or shut down the system etc.

I need an example of how this is coded or at least some more depth.
 
unplebeian said:
I understand the protocol itself but I am still uncertain about what the next step is. I understand that the FPGA can capture the MOSI data on the clock edge (depending on the SPI mode).
What is in the FPGA? What it does with the data depends on what configuration has been loaded. FPGAs are "field programmable", after all, so what program has been loaded?

We use FPGAs for all kinds of things at my work. In some of our circuits where we are using large FPGAs to emulate new microcontrollers (uCs), they are the SPI / I2C master, for example. It looks just like a uC like a PIC or similar.

In other circuits we use FPGAs in embedded control devices. In those cases the SPI link to the FPGA is used to set IO configurations and read back sensor data.
 
unplebeian said:
Hi Joshy,

I understand the protocol itself but I am still uncertain about what the next step is. I understand that the FPGA can capture the MOSI data on the clock edge (depending on the SPI mode). Let me give you an example.

Let's say we want to write the data from reg 0x5 using the SPI protocol. The FPGA receives a SPI command to do just that and stores the MISO data in some reg. But what happens next. How do we distinguish what to do next based on the MISO command - to either change a reg value or start execution of some other process or shut down the system etc.

I need an example of how this is coded or at least some more depth.

SPI is an interface, which is to say it is basically a communication protocol between devices.

What you describe above is the act of communicating, your FPGA has initiated a command over SPI, and the device has responded with some data (in reg 0x5 in your example). As far as understanding SPI itself, that's it, SPI has done its job once you have the data in your register.

Now what to do with that data is determined by the application, ie why are these two devices connected with SPI in the first place?

You might have your FPGA connected to an SPI temperature sensor. Your FPGA pings it, gets some numbers back. You connected your FPGA to a temperature sensor, therefore, you know the number that you get is a temperature, and you had to have had a reason to make this connection in the first place! Maybe your FPGA reads that number, checks against a limit, and if that limit is exceeded it maybe turns off a heater, for example.

Basically none of these things exist in a vacuum, they are solutions to a problem, SPI solves the inter-device communication problem, what you do with that inter-device communication capability is entirely up to you, the designer of an application.
 
I am trying to understand how transferring electric from the powerplant to my house is more effective using high voltage. The suggested explanation that the current is equal to the power supply divided by the voltage, and hence higher voltage leads to lower current and as a result to a lower power loss on the conductives is very confusing me. I know that the current is determined by the voltage and the resistance, and not by a power capability - which defines a limit to the allowable...

Similar threads

Replies
4
Views
735
  • · Replies 6 ·
Replies
6
Views
2K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • Sticky
  • · Replies 0 ·
Replies
0
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 823 ·
28
Replies
823
Views
129K
  • · Replies 3 ·
Replies
3
Views
4K