Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
CN-0413.ino
Go to the documentation of this file.
1 /***************************************************************************//**
2  * @file CN-0413.ino
3  * @brief A placeholder for CN-0413 program
4  * @author asdf (asdf.ghjk@analog.com)
5 ********************************************************************************
6  * Copyright 2017(c) Analog Devices, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * - Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * - Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  * - Neither the name of Analog Devices, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  * - The use of this software may or may not infringe the patent rights
22  * of one or more patent holders. This license does not release you
23  * from the requirement that you obtain separate licenses from these
24  * patent holders to use this software.
25  * - Use of the software either in source or binary form, must be run
26  * on or directly connected to an Analog Devices Inc. component.
27  *
28  * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31  * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33  * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39 
40 #include <Arduino.h>
41 #include <stdint.h>
42 #include <Linduino.h>
43 #include <UserInterface.h>
44 //#include <EEPROM.h>
45 #include <platform_drivers.h>
46 extern "C" {
47 #include "ad5933.h"
48 };
49 
51 {
52  GENERIC_I2C, // i2c type
53  0, // i2c id
54  100000, // i2c max speed (hz)
55  0x0D, // i2c slave address
56 };
57 
58 ad5933_init_param init_params =
59 {
60  i2c_params, // i2c parameters
61  AD5933_INTERNAL_SYS_CLK, //current_sys_clk
62  AD5933_CONTROL_EXT_SYSCLK, //current_clock_source
63  AD5933_GAIN_X1,//current_gain
64  AD5933_RANGE_400mVpp, //current_range
65 };
66 
67 ad5933_dev *device;
68 
69 int32_t connected = SUCCESS;
70 
71 void setup()
72 {
73  float tempdata;
74  Serial.begin(115200);
75 
76  // Give serial port a chance to initialize
77  delay(100);
78 
79  // Initialize
80  connected = ad5933_init(&device, init_params);
81  ad5933_reset(device);
82 
83 
84  if (connected != SUCCESS)
85  {
86  Serial.println("Connection to device failed :(");
87  }
88  else
89  {
90  Serial.println("Connection to device succeeded!");
91  Serial.println("Reading out temperature registers:");
92  tempdata = ad5933_get_temperature(device);
93  Serial.println(tempdata);
94  print_title();
95  }
96 }
97 
98 void loop()
99 {
100  // If there is no device, don't continue
101  if (connected != SUCCESS)
102  {
103  return;
104  }
105 
106  print_prompt();
107 
108  uint8_t user_command = read_int();
109  Serial.println(user_command);
110  Serial.flush();
111 
112  switch (user_command)
113  {
114  case 1:
116  break;
117 
118  case 2:
119  menu_2_asdf();
120  break;
121 
122  case 3:
123  menu_3_asdf();
124  break;
125 
126  case 4:
127  menu_4_asdf();
128  break;
129 
130  case 5:
131  //menu_5_critical();
132  break;
133 
134  case 9:
135  //EEPROM_WRITE_TEST();
136  break;
137 
138  default:
139  Serial.println(F("Invalid option"));
140  break;
141  }
142 }
143 
145 {
146  Serial.println(F("*****************************************************************"));
147  Serial.println(F("* EVAL-AD5933 Demonstration Program *"));
148  Serial.println(F("* *"));
149  Serial.println(F("* This program demonstrates communication with the AD5933 *"));
150  Serial.println(F("* 1MSPS, 12-bit Impedance Converter, Network Analyzer *"));
151  Serial.println(F("* *"));
152  Serial.println(F("* Set the baud rate to 115200 select the newline terminator. *"));
153  Serial.println(F("*****************************************************************"));
154 }
155 
157 {
158  Serial.println(F("\nCommand Summary:"));
159 
160  Serial.println(F(" 1- Read temperature"));
161  Serial.println(F(" 2- menu item 2"));
162  Serial.println(F(" 3- menu item 3"));
163  Serial.println(F(" 4- menu item 4"));
164  Serial.println(F(" X- Test & clear Linduino EEPROM"));
165  Serial.println();
166 
167  Serial.print(F("Enter a command: "));
168 }
169 
171 {
172  float tempdata;
173  Serial.println("\nReading out temperature:");
174  tempdata = ad5933_get_temperature(device);
175  Serial.print(tempdata);
176  Serial.println(" deg. C\n");
177  return 0;
178 }
179 
180 uint8_t menu_2_asdf()
181 {
182 
183  return 0;
184 }
185 
186 uint8_t menu_3_asdf()
187 {
188 
189 
190  return 0;
191 }
192 
193 uint8_t menu_4_asdf()
194 {
195 
196 
197  return 0;
198 }
199 
200 
ad5933_init_param init_params
Definition: CN-0413.ino:58
unsigned char user_command
i2c_init_param i2c_params
Definition: CN-0413.ino:50
Header File for Linduino Libraries and Demo Code.
static uint8_t menu_2_asdf()
Definition: CN-0413.ino:180
static int32_t connected
Definition: CN-0413.ino:69
static uint8_t menu_1_read_temperature()
Definition: CN-0413.ino:170
static uint8_t menu_4_asdf()
Definition: CN-0413.ino:193
static void print_prompt()
Definition: CN-0413.ino:156
Header file of Generic Platform Drivers.
static uint8_t menu_3_asdf()
Definition: CN-0413.ino:186
static void print_title()
Definition: CN-0413.ino:144
int32_t read_int()
static void loop()
Definition: CN-0413.ino:98
#define SUCCESS
Definition: LT_PMBus.h:62
static void setup()
Definition: CN-0413.ino:71
ad5933_dev * device
Definition: CN-0413.ino:67