I2C and SPI are widely used communication buses. This example is based on the I2C&SPI API available on VIPM to read the data of 4 different sensors through the both buses.
The example has been tested on the PXI-7854R board, but I expect it to work on other similar boards (cf. I2C&SPI API device compatibility). The goal is to read the temperature from two temperature sensors using the SPI Bus and to get the data from a Gyroscope and an accelerometer through the I2C bus. The FPGA hosts the circuitry of the generic layer for the I2C and the SPI and every command are sent from the host VI.
On the breadboard, everything is wired that way:
Power is supplied from an FPGA pin with 3.3V. The pull-up resistor mustn't be forgotten on each line (Value advised: 4.7k).
Note: on the ADXL 345, to activate the I2C: ground the SDO pin.
Sensors:
Hardware:
Software:
First of all, build the circuit with the different sensors and wire them to the FPGA through the SCB-68. If you are using the same hardware, I advise you to use the following pins:
SCB-68 Pin |
FPGA Pin |
Breadboard Pin |
67 |
Connector1/DIO37 |
SDA |
33 |
Connector1/DIO36 |
SCL |
32 |
Connector1/DIO24 |
MISO |
65 |
Connector1/DIO33 |
SCLK |
31 |
Connector1/DIO32 |
MOSI |
63 |
Connector1/DIO29 |
CS0 |
29 |
Connector1/DIO28 |
CS1 |
57 |
Connector1/DIO22 |
3.3V |
23 |
GND |
GND |
Once you are done, open the project.
You if you do not use the same device, you will need to reconfigure the FPGA IO: Open the FPGA and the VI main FPGA.vi
Then, modify the IO from the pin you choose on your FPGA.
Note: You can see that I modified the name of the FPGA's Pins to make the program easier to read.
Once you reconfigured your pins, recompile the FPGA. Once you are done, you can run the VI final_main.vi.
Note: to program the FPGA, you can just drag and drop the I2C Engine.vi on your FPGA code. It will make the whole generic layer for you.
LM74 :
ADXL 345:
MPU 6050:
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
HELLO,
I have a question. What does the clock rate mean in SPI WRITE/READ?
Thank you!
Hello Tianci,
The clock rate in the library is the frequency in MHz of the SPI clock line, we often use 1MHz. In my case I bypassed a conversion VI to directly set the clock divider.
Best,
Antoine
I started the program, but noticed that the values refresh very slowly (every 1 s or so). How can I get the highest possible data reading speed?