Interpreting SPI Commands in FPGA Applications

  • Thread starter Thread starter unplebeian
  • Start date Start date
AI Thread 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 Summary
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.
 
Hey guys. I have a question related to electricity and alternating current. Say an alien fictional society developed electricity, and settled on a standard like 73V AC current at 46 Hz. How would appliances be designed, and what impact would the lower frequency and voltage have on transformers, wiring, TVs, computers, LEDs, motors, and heating, assuming the laws of physics and technology are the same as on Earth?
While I was rolling out a shielded cable, a though came to my mind - what happens to the current flow in the cable if there came a short between the wire and the shield in both ends of the cable? For simplicity, lets assume a 1-wire copper wire wrapped in an aluminum shield. The wire and the shield has the same cross section area. There are insulating material between them, and in both ends there is a short between them. My first thought, the total resistance of the cable would be reduced...
I used to be an HVAC technician. One time I had a service call in which there was no power to the thermostat. The thermostat did not have power because the fuse in the air handler was blown. The fuse in the air handler was blown because there was a low voltage short. The rubber coating on one of the thermostat wires was chewed off by a rodent. The exposed metal in the thermostat wire was touching the metal cabinet of the air handler. This was a low voltage short. This low voltage...
Back
Top