Micheál Lambe
/
EVAL-ADE120x
ADE1202 Example proegram using ADE120x library files
main.cpp@1:cff2074f52d5, 2019-07-29 (annotated)
- Committer:
- malavikasaji
- Date:
- Mon Jul 29 23:59:40 2019 +0000
- Revision:
- 1:cff2074f52d5
- Parent:
- 0:4b7ec1ec0c7a
- Child:
- 2:2ebdd709cec0
Updating main.cpp template.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
malavikasaji | 0:4b7ec1ec0c7a | 1 | /* Copyright (c) 2019 Analog Devices, Inc. All rights reserved. |
malavikasaji | 0:4b7ec1ec0c7a | 2 | |
malavikasaji | 0:4b7ec1ec0c7a | 3 | Redistribution and use in source and binary forms, with or without modification, |
malavikasaji | 0:4b7ec1ec0c7a | 4 | are permitted provided that the following conditions are met: |
malavikasaji | 0:4b7ec1ec0c7a | 5 | - Redistributions of source code must retain the above copyright notice, |
malavikasaji | 0:4b7ec1ec0c7a | 6 | this list of conditions and the following disclaimer. |
malavikasaji | 0:4b7ec1ec0c7a | 7 | - Redistributions in binary form must reproduce the above copyright notice, |
malavikasaji | 0:4b7ec1ec0c7a | 8 | this list of conditions and the following disclaimer in the documentation |
malavikasaji | 0:4b7ec1ec0c7a | 9 | and/or other materials provided with the distribution. |
malavikasaji | 0:4b7ec1ec0c7a | 10 | - Modified versions of the software must be conspicuously marked as such. |
malavikasaji | 0:4b7ec1ec0c7a | 11 | - This software is licensed solely and exclusively for use with processors/products |
malavikasaji | 0:4b7ec1ec0c7a | 12 | manufactured by or for Analog Devices, Inc. |
malavikasaji | 0:4b7ec1ec0c7a | 13 | - This software may not be combined or merged with other code in any manner |
malavikasaji | 0:4b7ec1ec0c7a | 14 | that would cause the software to become subject to terms and conditions which |
malavikasaji | 0:4b7ec1ec0c7a | 15 | differ from those listed here. |
malavikasaji | 0:4b7ec1ec0c7a | 16 | - Neither the name of Analog Devices, Inc. nor the names of its contributors |
malavikasaji | 0:4b7ec1ec0c7a | 17 | may be used to endorse or promote products derived from this software without |
malavikasaji | 0:4b7ec1ec0c7a | 18 | specific prior written permission. |
malavikasaji | 1:cff2074f52d5 | 19 | - The use of this software ma y or may not infringe the patent rights of one or |
malavikasaji | 0:4b7ec1ec0c7a | 20 | more patent holders. This license does not release you from the requirement |
malavikasaji | 0:4b7ec1ec0c7a | 21 | that you obtain separate licenses from these patent holders to use this software. |
malavikasaji | 0:4b7ec1ec0c7a | 22 | |
malavikasaji | 0:4b7ec1ec0c7a | 23 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND |
malavikasaji | 0:4b7ec1ec0c7a | 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
malavikasaji | 0:4b7ec1ec0c7a | 25 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
malavikasaji | 0:4b7ec1ec0c7a | 26 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
malavikasaji | 0:4b7ec1ec0c7a | 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES |
malavikasaji | 0:4b7ec1ec0c7a | 28 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL |
malavikasaji | 0:4b7ec1ec0c7a | 29 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
malavikasaji | 0:4b7ec1ec0c7a | 30 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
malavikasaji | 0:4b7ec1ec0c7a | 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
malavikasaji | 0:4b7ec1ec0c7a | 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
malavikasaji | 0:4b7ec1ec0c7a | 33 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
malavikasaji | 0:4b7ec1ec0c7a | 34 | |
malavikasaji | 0:4b7ec1ec0c7a | 35 | 2019-01-10-7CBSD SLA |
malavikasaji | 0:4b7ec1ec0c7a | 36 | |
malavikasaji | 1:cff2074f52d5 | 37 | */ |
malavikasaji | 0:4b7ec1ec0c7a | 38 | |
malavikasaji | 1:cff2074f52d5 | 39 | /***Libraries***/ |
malavikasaji | 1:cff2074f52d5 | 40 | #include <stdio.h> /*Standard Library*/ |
malavikasaji | 1:cff2074f52d5 | 41 | #include "mbed.h" /*mbed header file*/ |
malavikasaji | 1:cff2074f52d5 | 42 | |
malavikasaji | 1:cff2074f52d5 | 43 | /***Defines for UART Protocol***/ |
malavikasaji | 1:cff2074f52d5 | 44 | #define BAUD_RATE 115200 /*Baud Rate*/ |
malavikasaji | 0:4b7ec1ec0c7a | 45 | |
malavikasaji | 1:cff2074f52d5 | 46 | /*Configure and instantiate UART protocol |
malavikasaji | 1:cff2074f52d5 | 47 | and baud rate*/ |
malavikasaji | 1:cff2074f52d5 | 48 | Serial port(USBTX, USBRX, BAUD_RATE); |
malavikasaji | 1:cff2074f52d5 | 49 | |
malavikasaji | 1:cff2074f52d5 | 50 | /***Function Declarations***/ |
malavikasaji | 0:4b7ec1ec0c7a | 51 | |
malavikasaji | 1:cff2074f52d5 | 52 | /*Print Information about Program's purpose*/ |
malavikasaji | 1:cff2074f52d5 | 53 | static void print_title(void); |
malavikasaji | 0:4b7ec1ec0c7a | 54 | |
malavikasaji | 1:cff2074f52d5 | 55 | /*Print Instructions on how to use Program*/ |
malavikasaji | 1:cff2074f52d5 | 56 | static void print_prompt(void); |
malavikasaji | 1:cff2074f52d5 | 57 | |
malavikasaji | 0:4b7ec1ec0c7a | 58 | int main() |
malavikasaji | 0:4b7ec1ec0c7a | 59 | { |
malavikasaji | 1:cff2074f52d5 | 60 | uint8_t user_command; /*User input variable*/ |
malavikasaji | 1:cff2074f52d5 | 61 | uint8_t connected = 1; /*Initialize SPI*/ |
malavikasaji | 1:cff2074f52d5 | 62 | |
malavikasaji | 1:cff2074f52d5 | 63 | print_title(); |
malavikasaji | 1:cff2074f52d5 | 64 | |
malavikasaji | 1:cff2074f52d5 | 65 | while(connected == 1) { |
malavikasaji | 1:cff2074f52d5 | 66 | print_prompt(); |
malavikasaji | 1:cff2074f52d5 | 67 | port.scanf("%2d", (int *) &user_command); |
malavikasaji | 1:cff2074f52d5 | 68 | switch (user_command) { |
malavikasaji | 1:cff2074f52d5 | 69 | case 1: |
malavikasaji | 1:cff2074f52d5 | 70 | port.printf("Case 1\n\n"); |
malavikasaji | 1:cff2074f52d5 | 71 | break; |
malavikasaji | 1:cff2074f52d5 | 72 | |
malavikasaji | 1:cff2074f52d5 | 73 | case 2: |
malavikasaji | 1:cff2074f52d5 | 74 | port.printf("Case 2\n\n"); |
malavikasaji | 1:cff2074f52d5 | 75 | //menu_item_1_conversion_read(dev); |
malavikasaji | 1:cff2074f52d5 | 76 | break; |
malavikasaji | 1:cff2074f52d5 | 77 | |
malavikasaji | 1:cff2074f52d5 | 78 | default: |
malavikasaji | 1:cff2074f52d5 | 79 | port.printf(" ***Illegal Entry****\n\n"); |
malavikasaji | 1:cff2074f52d5 | 80 | break; |
malavikasaji | 1:cff2074f52d5 | 81 | |
malavikasaji | 1:cff2074f52d5 | 82 | } |
malavikasaji | 0:4b7ec1ec0c7a | 83 | } |
malavikasaji | 1:cff2074f52d5 | 84 | return 0; |
malavikasaji | 0:4b7ec1ec0c7a | 85 | } |
malavikasaji | 0:4b7ec1ec0c7a | 86 | |
malavikasaji | 1:cff2074f52d5 | 87 | /***Function Definitions***/ |
malavikasaji | 1:cff2074f52d5 | 88 | |
malavikasaji | 1:cff2074f52d5 | 89 | |
malavikasaji | 1:cff2074f52d5 | 90 | /*Function to print the title block when program first starts. |
malavikasaji | 1:cff2074f52d5 | 91 | Parameters: None |
malavikasaji | 1:cff2074f52d5 | 92 | Return Value: None*/ |
malavikasaji | 1:cff2074f52d5 | 93 | void print_title() |
malavikasaji | 1:cff2074f52d5 | 94 | { |
malavikasaji | 1:cff2074f52d5 | 95 | port.printf("\n*****************************************************************\n"); |
malavikasaji | 1:cff2074f52d5 | 96 | port.printf("* EVAL-AD1234 Demonstration Program *\n"); |
malavikasaji | 1:cff2074f52d5 | 97 | port.printf("* *\n"); |
malavikasaji | 1:cff2074f52d5 | 98 | port.printf("* This program demonstrates how to measure strain gauge or *\n"); |
malavikasaji | 1:cff2074f52d5 | 99 | port.printf("* other form of a Wheatstone bridge sensors with the AD1234 *\n"); |
malavikasaji | 1:cff2074f52d5 | 100 | port.printf("* *\n"); |
malavikasaji | 1:cff2074f52d5 | 101 | port.printf("* *\n"); |
malavikasaji | 1:cff2074f52d5 | 102 | port.printf("* Set the baud rate to 115200 and select the newline terminator.*\n"); |
malavikasaji | 1:cff2074f52d5 | 103 | port.printf("* *\n"); |
malavikasaji | 1:cff2074f52d5 | 104 | port.printf("*****************************************************************\n"); |
malavikasaji | 1:cff2074f52d5 | 105 | } |
malavikasaji | 1:cff2074f52d5 | 106 | |
malavikasaji | 1:cff2074f52d5 | 107 | /*Function to Print Command Summary |
malavikasaji | 1:cff2074f52d5 | 108 | Parameters: None |
malavikasaji | 1:cff2074f52d5 | 109 | Return Value: None */ |
malavikasaji | 1:cff2074f52d5 | 110 | static void print_prompt() { |
malavikasaji | 1:cff2074f52d5 | 111 | port.printf("Command Summary\n"); |
malavikasaji | 1:cff2074f52d5 | 112 | port.printf(" 1 - Select ADC\n"); |
malavikasaji | 1:cff2074f52d5 | 113 | port.printf(" 2 - Select Power Mode\n"); |
malavikasaji | 1:cff2074f52d5 | 114 | port.printf(" x - Put More Menu Items Here\n"); |
malavikasaji | 1:cff2074f52d5 | 115 | } |
malavikasaji | 1:cff2074f52d5 | 116 | |
malavikasaji | 1:cff2074f52d5 | 117 | void menu_1_function1() |
malavikasaji | 1:cff2074f52d5 | 118 | { |
malavikasaji | 1:cff2074f52d5 | 119 | port.printf("In function 1\n"); |
malavikasaji | 1:cff2074f52d5 | 120 | } |
malavikasaji | 1:cff2074f52d5 | 121 | |
malavikasaji | 1:cff2074f52d5 | 122 | void menu_2_function2() |
malavikasaji | 1:cff2074f52d5 | 123 | { |
malavikasaji | 1:cff2074f52d5 | 124 | port.printf("In function 2\n"); |
malavikasaji | 1:cff2074f52d5 | 125 | } |
malavikasaji | 1:cff2074f52d5 | 126 |