Research Article Volume 6 Issue 1
Servicio Nacional de Aprenizaje Bogota, Colombia
Correspondence: Juan Carlos Maya Gonzalez, Servicio Nacional de Aprenizaje Bogota, Colombia, Tel 3005159575
Received: February 17, 2023 | Published: March 27, 2023
Citation: Gonzalez JCM. Implementation of I2C and SPI communication protocol for temperature and acceleration measurement at FPGA. Open Access J Sci. 2023;6(1):19-22. DOI: 10.15406/oajs.2023.06.00188
This document presents the development of the I2C and SPI communication protocols in the VHDL hardware description language, its implementation was carried out on the Xilinx Nexys 4 DDR FPGA board with temperature sensors (ADXL362) and accelerometer (ADT742). whose chips are integrated into the board. The temperature sensor communicates with the I2C protocol and the accelerometer with the SPI protocol, both communications were integrated into the project and can be selected through the switches provided by the FPGA board. The experimental results carried out demonstrate the reliability of the communication given the precision of the data obtained.
Keywords: I2C protocol, SPI protocol, FPGA, temperature sensor, accelerometer
Communication protocols are standards that allow control and process elements to get in contact with the measuring instrument, they are based on obtaining measurement signals by hardware elements that capture information of certain physical parameters and convert them into signals that can be interpreted by electronic systems; a good communication protocol allows obtaining reliable and accurate data. In the electronics industry, I2C and SPI communication is frequently used in instrumentation systems, projects have been developed in which it is essential to use these protocols. In1 an instrumentation system that analyzes the environmental temperature variation as a precursor of earthquake prediction using I2C is presented, this is composed of a temperature sensor coupled to an embedded system to allow accurate detection of the variation in physical parameters; the interface with the microcontroller additionally allows sending an audible and visual alarm when the parameters are exceeded beyond a certain critical threshold. In2 a motorcycle intelligent safety system is presented, the proposed development includes a helmet controlled safety system in which the motorcycle ignition is only activated when the helmet is properly worn by the rider; this system also incorporates other features such as global positioning system, automatic head light control and real time display.
SPI communication has also been the subject of research, due to the number of electronic devices in aircraft that are expanding exponentially, in3 a new design and a new application of bus control communications in avionics is proposed, combining the advantages of SPI communication and Ip-Core FPGAs. Finally, in4 an SPI-based integrated control system for a 5 degrees of freedom industrial manipulator robot is presented, a set of microcontrollers is used to perform the control task, each one calculates its own control signal to achieve the joint movements; this system incorporates an 8-bit master-slave microcontroller scheme, with one driving master and 5 slaves, in order to exchange control information via SPI network. The motivation of this project is to develop a communication system for I2C and SPI peripherals, and to demonstrate the operation of the developed blocks through the temperature and accelerometer sensors integrated in the Nexys 4 DDR FPGA board, technology that allows the use of very high speeds compared to other tools.
System overview
The system implementation process consists of three stages: communication development, sensor configuration and data reception.
Development of communication
For the development of the communication, a program was developed in the VHDL hardware description language, in which the parameters and operating conditions of the SPI protocol and the i2C protocol were established. The SPI communication protocol consists of 4 signals, Master Out Slave In (MOSI), Master in Slave Out (MISO), the clock (SCK), and Slave Select (SS). In this communication you have a master and one or more slaves, in this project the "master" will be the FPGA board and the "slave" will be the accelerometer. In the I2C communication protocol, two lines SCL (data transfer synchronization clock line) and SDA (data line) are specified. Both lines are connected to the device to be communicated. Devices connected to the I2C bus can behave as "master" or "slave". The "master" is the one that generates the SCL signal and the one that generates the information requests. The "slaves" only send the information requested by the "master". In our case, the "master" will be the FPGA board and the "slave" will be the temperature sensor.
Sensor configuration
The Nexys 4 DDR FPGA board includes a 3-axis ADXL362 accelerometer with SPI communication, it operates as a slave and works in mode 0, this SPI port uses a multi-byte structure in which the first byte establishes the read or write command, the second byte determines the register to write or read, and finally ends with the values to write or read. Initially the sensor will be written to establish its configuration, and finally the repetitive readings of the different accelerations (x,y,z) sensed are made. Specifically, it is indicated with the command 0x0A that the sensor is in write mode, followed by the value 0x2D to configure the sensor in on mode with the word 0x02. Once configured, the command 0x0B is sent as read mode and the data to be read is specified, in this case 0x08 to read data from the x-axis, 0x09 from the axis and 0x0A from the z-axis. The 8 bits of data received are obtained and the conversion is done to display them on a 7-segment display. The Nexys 4 DDR FPGA board also includes an ADT7420 temperature sensor, which acts as a slave device using the I2C communication scheme and is rated to operate in the temperature range of -40◦ C to +150◦ C. The I2C master must specify a slave address (0x4B), followed by a bit indicating whether the communication is a read (1) or a write (0). Once the specifications are made for communication, the data transfer takes place.
Data reception
The measurements read from the accelerometer are received in a byte expressed in binary and for negative values in 2's complement, once the axis to be measured is selected, the data is received and converted to be displayed on a 7-segment display. For I2C communication, 16 bits are received in the temperature value register, here the TCRIT value (temperature greater than 147◦C), the THIGH setpoint register (temperature greater than 64◦C) and the TLW setpoint register (temperature less than 10◦C) are integrated. The MSB is the temperature sign bit; the three LSBs, Bit 0 to Bit 2, when turned on, are not part of the temperature conversion result and are flag bits for TCRIT, THIGH and TLOW. To calculate the temperature value in degrees Celsius, the following conversion is performed.
To read and display the information provided by the temperature and acceleration sensors included in the Nexys 4 board, the general scheme shown in Figure 1 is proposed. The information is read by means of the SDA and SCl signals for the temperature sensor, while in the case of acceleration, the MISO, MOSI, SCK and SS signals are used. The results are displayed on the array of 8 seven-segment displays included on the board. Figure 2 shows the three hardware blocks implemented in the Xilinx XC7A100T FPGA, the core of the Nexys 4 board. The general structure of the project includes two modules for communication with the sensors and the multiplexing of the information to the displays, according to the reading of 4 switches.
Acceleration reading
For the reading of the acceleration presented in Figure 2, the SPI module and controller includes internally the implementation of the blocks established in Figure 3. In it, the interconnection of two state machines is established, one on the rising edge of the SCK line and the other on the falling edge. Additionally, the state machine generates the orders to the SPI module in order to generate the information readable on the displays. The structuring of the state machine is shown in Figure 4, where the chain of states to read one by one the acceleration data in x, y and z is established. Initially, as established in the section Configuration of the Senses, there is a state in which the commands to turn on the accelerometer are performed (measurement mode), then the reading of the three accelerations is performed cyclically. Additionally, a parallel process is included that is continuously decoding in bcd the acceleration data for the next representation of the information on the displays by means of an additional decoder.
Temperature reading
Figure 5 shows the general structure of the blocks in the I2C module to generate the appropriate SCL and SDA signals to obtain the instantaneous temperature information on the displays. These are four state machines running in parallel according to the rising edge, falling edge, rising offset edge and falling offset edge; all these edges detected from the generated SCK signal (1MHZ). The proposal includes these four machines responding to the need to comply with the minimum and maximum times of the I2C protocol and the ADXL362 sensor. In the case of the I2C module, the commands are generated by a KCSPM6 processor. Following one by one the instructions previously compiled in the ROM memory block, it allows to read and decode the information for its next representation in the displays. Figure 6 shows the algorithm implemented in assembly language, first the sensor address is sent (4B) plus the intention to read according to the I2c protocol, then the arrival of two bytes with the instantaneous temperature information (MSB and LSB) is expected, the cycle is repeated indefinitely with the continuous inclusion of the 7-segment coding instructions (data conversion and printing block) Figure 6–9.
The following pictures show how the system works when, using the switches, it is configured for the acceleration reading in each of the axes. The pictures show how, by moving the board in the appropriate direction, different results are obtained. The variation is obtained given the change of the component in the chosen direction of the gravity acceleration vector always orthogonal to the earth's surface. Finally, Figure 10 presents the ambient temperature measurement, applying external heat, the linearity of the sensor measurement is observed.5–9
The top-down structuring for the development of the presented application allows segmenting the project in macro blocks that at the end are properly interconnected. The work consists of debugging the functioning of the blocks for their subsequent correct operation. Once the SPI and I2C communication with the sensors is established, the processing of the information is not complex given the linearity and stability of the measurements, it is enough to decode the information to generate an adequate display of the information. The use of processors such as picoblaze (KCSPM6) and state machines allow, by means of algorithms and short state strings, the generation of commands to SPI and I2C modules for communication with peripherals.
None.
The author declares there is no conflict of interest.
©2023 Gonzalez. This is an open access article distributed under the terms of the, which permits unrestricted use, distribution, and build upon your work non-commercially.