EVAL-AD593x Mbed Project.
Dependencies: platform_drivers
Diff: main.cpp
- Revision:
- 0:86671e9c8db0
- Child:
- 1:bd8aea0d51e0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 03 17:00:18 2019 +0000 @@ -0,0 +1,158 @@ +/* Copyright (c) 2019 Analog Devices, Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + - Modified versions of the software must be conspicuously marked as such. + - This software is licensed solely and exclusively for use with processors/products + manufactured by or for Analog Devices, Inc. + - This software may not be combined or merged with other code in any manner + that would cause the software to become subject to terms and conditions which + differ from those listed here. + - Neither the name of Analog Devices, Inc. nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + - The use of this software ma y or may not infringe the patent rights of one or + more patent holders. This license does not release you from the requirement + that you obtain separate licenses from these patent holders to use this software. + +THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, +TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN +NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL +PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +2019-01-10-7CBSD SLA + +*/ + +/***Libraries***/ +#include <stdio.h> /*Standard Library*/ +#include "mbed.h" /*mbed header file*/ +#include "AD593x.h" + +/***Defines for UART Protocol***/ +#define BAUD_RATE 115200 /*Baud Rate*/ + +/*Configure and instantiate UART protocol + and baud rate*/ +Serial port(USBTX, USBRX, BAUD_RATE); + +AD1234 device(D10); +// If you have a second device on board, define it as a new device. For e.g. AD1234 device2(D9); + +/***Function Declarations***/ +static void setup_devices(void); +static void print_title(void); +static void print_prompt(void); +static void menu_1_function1(void); +static void menu_2_function2(void); +static void menu_3_function3(void); + +int main() +{ + uint8_t user_command; /*User input variable*/ + uint8_t connected = 1; /*Initialize SPI*/ + + print_title(); + + while(connected == 1) { + print_prompt(); + port.scanf("%2d", (int *) &user_command); + port.printf("%2d\n", user_command); + switch (user_command) { + case 1: + menu_1_function1(); + break; + + case 2: + menu_2_function2(); + break; + + case 3: + menu_3_function3(); + break; + + default: + port.printf(" ***Invalid Entry****\n\n"); + break; + + } + } + return 0; +} + +/***Function Definitions***/ + + +static void setup_devices(void) +{ + device.frequency(1000000); + //device2.frequency(2000000); +} + + +/*Function to print the title block when program first starts + Parameters: None + Return Value: None*/ +void print_title() +{ + port.printf("\n*****************************************************************\n"); + port.printf("* EVAL-AD1234 Demonstration Program *\n"); + port.printf("* *\n"); + port.printf("* This program demonstrates how to measure strain gauge or *\n"); + port.printf("* other form of a Wheatstone bridge sensors with the AD1234 *\n"); + port.printf("* *\n"); + port.printf("* *\n"); + port.printf("* Set the baud rate to 115200 and select the newline terminator.*\n"); + port.printf("* *\n"); + port.printf("*****************************************************************\n"); +} + +/*Function to print command summary + Parameters: None + Return Value: None */ +void print_prompt() { + port.printf("\nCommand Summary\n"); + port.printf(" 1 - CS high\n"); + port.printf(" 2 - CS low\n"); + port.printf(" 3 - Spi transaction\n"); + port.printf(" x - Put More Menu Items Here\n"); + port.printf("Select an option: "); +} + + +/*Function to + Parameters: None + Return Value: None */ +void menu_1_function1() +{ + device.AD1234_function1(); + port.printf("In function 1\n"); +} + + +/*Function to + Parameters: None + Return Value: None */ +void menu_2_function2() +{ + device.AD1234_function2(); + port.printf("In function 2\n"); +} + +void menu_3_function3() +{ + device.write_16b_spi(0x5050); + port.printf("In function 3\n"); +} \ No newline at end of file