Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Chapter 14 ■ How Fast Can You Run? Ask the Accelerometer!

uart_dout_o => GPIO_J3_39, -- yellow colour wire


uart_din_i => GPIO_J3_40, -- orange colour wire
i2c_scl => ADT7420_SCL,
i2c_dat => ADT7420_SDA ,
spi_sclk => ADXL362_SCLK,
spi_csn => ADXL362_CS,
spi_mosi => ADXL362_MOSI,
spi_miso => ADXL362_MISO,
spi_int1 => ADXL362_INT1,
spi_int2 => ADXL362_INT2
);

end architecture arch;

14.3.4 Hardware Setup for the Accelerator Sensor Project Design


1.
Use the exact same hardware setup as in Chapter 13. Follow the section
“Hardware Setup for the Temperature Sensor Project Design” in Chapter 13 if
you need a reminder or if you skipped that chapter.
2.
You can now connect the programmer USB cable to directly upload the image to
the FPGA.
3.
Connect the USB side of the USB to UART cable to the PC.
4.
Connect the FPGA programmer.
5.
The next step is to use RealTerm to send requests to the SPI and read-back
registers

14.3.5 Initialize the Accelerometer—ADXL362


Step 1: Send a status request command to the board to check that the connection is set up correctly.
Command = 0x80 0x00 0x00 0x00 0x00 0x00
You should able to see the read-back as in Figure 14-19.

338
Chapter 14 ■ How Fast Can You Run? Ask the Accelerometer!

Figure 14-19.  Send a status request command and see the status coming back

Step 2: Set the SPI master clock speed, clock polarity, and phase. Figure 14-20 shows the setup
command and status being read back.
Command = 0x01 0x00 0x00 0x00 0x00 0x40
This command setting the clk_div is 0x40. By the equation we shared earlier in the chapter, the SPI
SCLK will run at 230.5 kHz.

339
Chapter 14 ■ How Fast Can You Run? Ask the Accelerometer!

Figure 14-20.  SPI master setup commands

Step 3: This step is based on the ADXL362 datasheet to enable "applications information autonomous
motion switch" with startup routine.
Following is the command list to program the ADXL362 register from 0x20 to 0x26 (Figure 14-21 shows
the commands):
1.
0x01 0x01 0x80 0x00 0x00 0x0a 0x01 0x01 0x80 0x00 0x00 0x20 0x01
0x01 0x80 0x00 0x00 0xFA
2.
0x01 0x01 0x80 0x00 0x00 0x00 0x01 0x01 0x80 0x00 0x00 0x02 0x01
0x01 0x80 0x00 0x00 0x96
3.
0x01 0x01 0x80 0x00 0x00 0x00 0x01 0x01 0x80 0x00 0x00 0x1E 0x01
0x01 0x80 0x00 0x01 0x00

340
Chapter 14 ■ How Fast Can You Run? Ask the Accelerometer!

Figure 14-21.  SPI master setup commands—2

4.
Write 0x3F to Register 0x27 which configures motion detection in loop mode and
enables referenced activity and inactivity detection.
0x01 0x01 0x80 0x00 0x00 0x0a 0x01 0x01 0x80 0x00 0x00 0x27 0x01
0x01 0x80 0x00 0x01 0x3f
5.
Write 0x00 to register 0x28 and 0x80 to register 0x29 to configure FIFO.
0x01 0x01 0x80 0x00 0x00 0x0a 0x01 0x01 0x80 0x00 0x00 0x28 0x01
0x01 0x80 0x00 0x00 0x00 0x01 0x01 0x80 0x00 0x01 0x80

6.
Write 0x40 to register 0x2a and 0x01 to register 0x2b to map AWAKE bit to the INT2.
0x01 0x01 0x80 0x00 0x00 0x0a 0x01 0x01 0x80 0x00 0x00 0x2a 0x01
0x01 0x80 0x00 0x00 0x40 0x01 0x01 0x80 0x00 0x01

7.
Write 0x13 to register 0x2c to configure general device settings.
0x01 0x01 0x80 0x00 0x00 0x0a 0x01 0x01 0x80 0x00 0x00 0x2c 0x01
0x01 0x80 0x00 0x01 0x13

341
Chapter 14 ■ How Fast Can You Run? Ask the Accelerometer!

8.
The last one is to begin the measurement in wake-up mode which writes 0x0a to
register 0x2D.
0x01 0x01 0x80 0x00 0x00 0x0a 0x01 0x01 0x80 0x00 0x00 0x2d 0x01
0x01 0x80 0x00 0x01 0x0a
Five seconds after the last command, all of the LEDs should be off. You can to shake the board to see
what happens. LED 0 will turn on when the device is AWAKE.
Send the following command:

0x01 0x01 0x80 0x00 0x00 0x0b 0x01 0x01 0x80 0x00 0x00 0x08 0x01 0x01 0x80 0x00 0x00 0x00
0x01 0x01 0x80 0x00 0x00 0x00 0x01 0x01 0x80 0x00 0x01 0x00
0x80 0x00 0x00 0x00 0x00 0x00

It will be able to read back three axis acceleration values. A is X-axis, B is Y-axis, and C is Z-axis
(Figure 14-22).

Figure 14-22.  Request xyz-axis acceleration value

342

You might also like