Skip to content

Latest commit

 

History

History
49 lines (43 loc) · 2.36 KB

File metadata and controls

49 lines (43 loc) · 2.36 KB

Phase 4: Serial Peripheral Interface (SPI)

Learning Objectives

  • SPI communication
  • Advanced driver development
  • Accelerometers
  • Reading datasheets
  • Running code on EVT hardware

Summary

The next communication protocol to cover is the Serial Peripheral Interface (SPI, pronounced "spy"). You'll use this protocol to communicate between the uC and a 3-axis accelerometer. An accelerometer is an special integrated circuit (IC) that is capable of sensing the acceleration of the chip. For our purposes, we're going simply read the acceleration of all three axes, convert it to G-force, and print it out. You'll still need the Saleae and FTB, but you'll need to switch out the TMP117 board for the ADXL345 board. For this phase, the header file hasn't been provided for you, so you'll have to write that yourself. The files you need to edit are include/dev/ADXL345.hpp, src/dev/ADXL345.cpp, and targets/phase4/main.cpp.

Task Breakdown

  1. Read the SPI documentation.
  2. Read the datasheets.md section about the ADXL345 datasheet.
  3. Write the header file for the ADXL345, so that it can be used to read all three static acceleration axes.
  4. Implement the functions defined in the header file and initialize the ADXL345 sensor.
  5. Write the target code to call the functions and print all accelerations in g-force over UART.
  6. Use the Saleae to decode the waveforms on CS, SCK, MOSI, and MISO and confirm the data matches what is output over UART.

Suggestions

  • Read the SPI documentation.
  • Fully plan out the ADXL345 class in the header file before starting on the implementation.
  • Make dedicated read and write methods for communicating with the ADXL345 to promote code reuse.
  • Look at the SPI sample in EVT-core for an example.

Completion

Once you have completed your implementation, you should see a g-force on the z-axis around 1 due to gravity. Try standing the board up on one end to see if the acceleration shifts to one of the other axes. Try it again on the perpendicular axis. You should be able to see a positive and negative acceleration due to gravity on each axis. When you're happy with the performance, have a senior member look at your Saleae output and your code. If it looks good, you can start on phase 5.