Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Lab_6_WaG by
spi.cpp
00001 /****************************************************************************** 00002 * EECS 397 00003 * 00004 * Assignment Name: Lab 6: WaG 00005 * 00006 * Authors: Sam Morrison and Phong Nguyen 00007 * File name: spi.cpp 00008 * Purpose: Driver for SPI functions 00009 * 00010 * Created: 03/01/2018 00011 * Last Modified: 03/29/2018 00012 * 00013 ******************************************************************************/ 00014 00015 #include "mbed.h" 00016 #include "io_pins.h" 00017 #include "spi.h" 00018 #include <stdlib.h> 00019 #include <stdio.h> 00020 #include <string.h> 00021 00022 extern SPI wag_spi; 00023 00024 DigitalOut dsp_ncs(DSP_AS1107_NCS);//This sets up the chip select for the AS1107 00025 00026 00027 extern struct spi_cfg as1107; 00028 00029 00030 /* 00031 * void spi_send(struct spi_cfg spi_config, int spi_data); 00032 * Description: sends an instruction to an SPI device 00033 * 00034 * Inputs: 00035 * Parameters: 00036 * struct spi_cfg spi_config: structure containing device qualities 00037 int spi_data: command to write to device 00038 * Globals: 00039 * 00040 * Outputs: 00041 * Returns: void 00042 */ 00043 void spi_send(struct spi_cfg spi_config, int spi_data) { 00044 static int previous_id = SPI_NO_ID; 00045 spi_config.spi_ncs = 1; 00046 if (previous_id != spi_config.spi_id) { 00047 //send config data to master 00048 previous_id = spi_config.spi_id; 00049 wag_spi.frequency(spi_config.spi_freq); 00050 wag_spi.format(spi_config.spi_no_bits, 0); 00051 } 00052 spi_config.spi_ncs = 0; 00053 wag_spi.write(spi_data); 00054 spi_config.spi_ncs = 1; 00055 } 00056
Generated on Mon Jul 18 2022 00:36:30 by
