Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
hello_world.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1962C Demonstration Board
3 LTC3880, LTC2974, LTC2977: Power Management Solution for Application Processors
4 
5 @verbatim
6 
7 NOTES
8  Setup:
9  Set the terminal baud rate to 115200 and select the newline terminator.
10 
11 @endverbatim
12 
13 http://www.linear.com/product/LTC3880
14 
15 http://www.linear.com/product/LTC2974
16 
17 http://www.linear.com/product/LTC2977
18 
19 http://www.linear.com/demo/DC1962C
20 
21 
22 Copyright 2018(c) Analog Devices, Inc.
23 
24 All rights reserved.
25 
26 Redistribution and use in source and binary forms, with or without
27 modification, are permitted provided that the following conditions are met:
28  - Redistributions of source code must retain the above copyright
29  notice, this list of conditions and the following disclaimer.
30  - Redistributions in binary form must reproduce the above copyright
31  notice, this list of conditions and the following disclaimer in
32  the documentation and/or other materials provided with the
33  distribution.
34  - Neither the name of Analog Devices, Inc. nor the names of its
35  contributors may be used to endorse or promote products derived
36  from this software without specific prior written permission.
37  - The use of this software may or may not infringe the patent rights
38  of one or more patent holders. This license does not release you
39  from the requirement that you obtain separate licenses from these
40  patent holders to use this software.
41  - Use of the software either in source or binary form, must be run
42  on or directly connected to an Analog Devices Inc. component.
43 
44 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
45 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
46 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
48 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
50 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
52 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
55 
56 /*! @file
57  @ingroup DC1962
58 */
59 
60 #include <Arduino.h>
61 #include <stdint.h>
62 #include <Linduino.h>
63 #include <UserInterface.h>
64 #include <LT_Wire.h>
65 #include <LT_PMBus.h>
66 #include <LT_SMBusPec.h>
67 #include <LT_PMBusMath.h>
68 #include <LT_SMBus.h>
69 #include <LT_I2CBus.h>
70 #include <LT_SMBusGroup.h>
71 #include <LT_FaultLog.h>
72 #include <LT_SMBusNoPec.h>
73 #include <LT_SMBusBase.h>
74 
75 #define LTC3880_I2C_ADDRESS 0x30
76 #define LTC2974_I2C_ADDRESS 0x32
77 #define LTC2977_I2C_ADDRESS 0x33
78 
79 // Global variables
80 static uint8_t ltc3880_i2c_address;
81 static uint8_t ltc2974_i2c_address;
82 static uint8_t ltc2977_i2c_address;
83 static LT_SMBus *smbus = new LT_SMBusNoPec();
84 static LT_PMBus *pmbus = new LT_PMBus(smbus);
85 
86 //! Initialize Linduino
87 //! @return void
88 void setup()
89 {
90  Serial.begin(115200); //! Initialize the serial port to the PC
91  print_title();
95  print_prompt();
96 }
97 
98 //! Repeats Linduino loop
99 //! @return void
100 void loop()
101 {
102  uint8_t user_command;
103  uint8_t res;
104  uint8_t model[7];
105  uint8_t revision[10];
106  uint8_t *addresses = NULL;
107 
108  if (Serial.available()) //! Checks for user input
109  {
110  user_command = read_int(); //! Reads the user command
111  if (user_command != 'm')
112  Serial.println(user_command);
113 
114  switch (user_command) //! Prints the appropriate submenu
115  {
116  case 1:
117  menu_1_basic_commands(); // Print single-ended voltage menu
118  break;
119  case 2:
123  delete smbus;
124  delete pmbus;
125  smbus = new LT_SMBusPec();
126  pmbus = new LT_PMBus(smbus);
127  break;
128  case 3:
132  delete smbus;
133  delete pmbus;
134  smbus = new LT_SMBusNoPec();
135  pmbus = new LT_PMBus(smbus);
136  break;
137  case 4:
138  addresses = smbus->probe(0);
139  while (*addresses != 0)
140  {
141  Serial.print(F("ADDR 0x"));
142  Serial.println(*addresses++, HEX);
143  }
144  break;
145  case 5 :
146  pmbus->startGroupProtocol();
147  pmbus->reset(ltc3880_i2c_address);
150  pmbus->executeGroupProtocol();
151  default:
152  Serial.println(F("Incorrect Option"));
153  break;
154  }
155  print_prompt();
156  }
157 
158 }
159 
160 // Function Definitions
161 
162 //! Prints the title block when program first starts.
163 //! @return void
165 {
166  Serial.print(F("\n*****************************************************************\n"));
167  Serial.print(F("* DC1962C Hello World Demonstration Program *\n"));
168  Serial.print(F("* *\n"));
169  Serial.print(F("* This program demonstrates how to send and receive data from *\n"));
170  Serial.print(F("* the LTC1962C demo board. *\n"));
171  Serial.print(F("* *\n"));
172  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
173  Serial.print(F("* *\n"));
174  Serial.print(F("*****************************************************************\n"));
175 }
176 
177 //! Prints main menu.
178 //! @return void
180 {
181  Serial.print(F("\n 1-Basic Commands\n"));
182  Serial.print(F(" 2-PEC On\n"));
183  Serial.print(F(" 3-PEC Off\n"));
184  Serial.print(F(" 4-Bus Probe\n"));
185  Serial.print(F(" 5-Reset\n"));
186  Serial.print(F("\nEnter a command:"));
187 }
188 
189 //! Prints a warning if the demo board is not detected.
190 //! @return void
192 {
193  Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
194 }
195 
196 //! Print all voltages
197 //! @return void
199 {
200  float voltage;
201  uint8_t page;
202 
203  for (page = 0; page < 2; page++)
204  {
205  pmbus->setPage(ltc3880_i2c_address, page);
206  voltage = pmbus->readVout(ltc3880_i2c_address, false);
207  Serial.print(F("LTC3880 VOUT "));
208  Serial.println(voltage, DEC);
209  }
210 
211  for (page = 0; page < 4; page++)
212  {
213  pmbus->setPage(ltc2974_i2c_address, page);
214  voltage = pmbus->readVout(ltc2974_i2c_address, false);
215  Serial.print(F("LTC2974 VOUT "));
216  Serial.println(voltage, DEC);
217  }
218 
219  for (page = 0; page < 8; page++)
220  {
221  pmbus->setPage(ltc2977_i2c_address, page);
222  voltage = pmbus->readVout(ltc2977_i2c_address, false);
223  Serial.print(F("LTC2977 VOUT "));
224  Serial.println(voltage, DEC);
225  }
226 
227 }
228 
229 //! Print all currents
230 //! @return void
232 {
233  float current;
234  uint8_t page;
235 
236  for (page = 0; page < 2; page++)
237  {
238  pmbus->setPage(ltc3880_i2c_address, page);
239  current = pmbus->readIout(ltc3880_i2c_address, false);
240  Serial.print(F("LTC3880 IOUT "));
241  Serial.println(current, DEC);
242  }
243 
244  for (page = 0; page < 4; page++)
245  {
246  pmbus->setPage(ltc2974_i2c_address, page);
247  current = pmbus->readIout(ltc2974_i2c_address, false);
248  Serial.print(F("LTC2974 IOUT "));
249  Serial.println(current, DEC);
250  }
251 
252  // LTC2977 does not measure current on a DC1962C
253 
254 }
255 
256 //! Print all status bytes and words
257 //! @return void
259 {
260  uint8_t b;
261  uint16_t w;
262  uint8_t page;
263 
264  for (page = 0; page < 2; page++)
265  {
266  Serial.print(F("PAGE "));
267  Serial.println(page, DEC);
268  pmbus->setPage(ltc3880_i2c_address, page);
270  Serial.print(F("LTC3880 STATUS BYTE 0x"));
271  Serial.println(b, HEX);
273  Serial.print(F("LTC3880 STATUS WORD 0x"));
274  Serial.println(w, HEX);
275  }
276 
277  for (page = 0; page < 4; page++)
278  {
279  Serial.print(F("PAGE "));
280  Serial.println(page, DEC);
281  pmbus->setPage(ltc2974_i2c_address, page);
283  Serial.print(F("LTC2974 STATUS BYTE 0x"));
284  Serial.println(b, HEX);
286  Serial.print(F("LTC2974 STATUS WORD 0x"));
287  Serial.println(w, HEX);
288  }
289 
290  for (page = 0; page < 8; page++)
291  {
292  Serial.print(F("PAGE "));
293  Serial.println(page, DEC);
294  pmbus->setPage(ltc2977_i2c_address, page);
296  Serial.print(F("LTC2977 STATUS BYTE 0x"));
297  Serial.println(b, DEC);
299  Serial.print(F("LTC2977 STATUS WORD 0x"));
300  Serial.println(w, HEX);
301  }
302 }
303 
304 //! Sequence off then on
305 //! @return void
307 {
308  pmbus->sequenceOffGlobal();
309  delay (2000);
310  pmbus->sequenceOnGlobal();
311 }
312 
313 //! Margin high
314 //! @return void
316 {
317  pmbus->marginHighGlobal();
318 }
319 
320 //! Margin low
321 //! @return void
323 {
324  pmbus->marginLowGlobal();
325 }
326 
327 //! Go to nominal
328 //! @return void
330 {
331  pmbus->sequenceOnGlobal();
332 }
333 
334 //! Display menu 1
336 {
337  uint8_t user_command;
338 
339  do
340  {
341  //! Displays the Read/Write menu
342  Serial.print(F(" 1-Read All Voltages\n"));
343  Serial.print(F(" 2-Read All Currents\n"));
344  Serial.print(F(" 3-Read All Status\n"));
345  Serial.print(F(" 4-Sequence Off/On\n"));
346  Serial.print(F(" 5-Margin High\n"));
347  Serial.print(F(" 6-Margin Low\n"));
348  Serial.print(F(" 7-Margin Off\n"));
349  Serial.print(F(" 8-Set LTC3880 PAGE 0 to 0.87V\n"));
350  Serial.print(F(" 9-Set LTC3880 PAGE 0 to 0.78V\n"));
351  Serial.print(F(" m-Main Menu\n"));
352  Serial.print(F("\nEnter a command: "));
353 
354  user_command = read_int(); //! Reads the user command
355  if (user_command == 'm') // Print m if it is entered
356  {
357  Serial.print(F("m\n"));
358  }
359  else
360  Serial.println(user_command); // Print user command
361 
362  switch (user_command)
363  {
364  case 1:
366  break;
367  case 2:
369  break;
370  case 3:
372  break;
373  case 4:
374  sequence_off_on();
375  break;
376  case 5:
377  margin_high();
378  break;
379  case 6:
380  margin_low();
381  break;
382  case 7:
383  margin_off();
384  break;
385  case 8:
386  pmbus->setPage(ltc3880_i2c_address, 0x00);
387  pmbus->setVout(ltc3880_i2c_address, 0.87);
388  break;
389  case 9:
390  pmbus->setPage(ltc3880_i2c_address, 0x00);
391  pmbus->setVout(ltc3880_i2c_address, 0.78);
392  break;
393  default:
394  if (user_command != 'm')
395  Serial.println(F("Invalid Selection"));
396  break;
397  }
398  }
399  while (user_command != 'm');
400 }
401 
402 
static void margin_high()
Margin high.
static uint8_t ltc3880_i2c_address
Definition: hello_world.ino:80
unsigned char user_command
LTC SMBus Support: API for a shared SMBus layer.
#define LTC3880_I2C_ADDRESS
Definition: hello_world.ino:75
LTC SMBus Support: Implementation for a shared SMBus layer.
static void print_all_voltages()
Print all voltages.
LTC SMBus Support: Implementation for a shared SMBus layer.
void reset(uint8_t address)
Issue reset to one device.
Definition: LT_PMBus.cpp:2912
uint8_t readStatusByte(uint8_t address)
Get the status byte.
Definition: LT_PMBus.cpp:2423
Header File for Linduino Libraries and Demo Code.
static void menu_1_basic_commands()
Display menu 1.
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
float readIout(uint8_t address, bool polling)
Get the measured output current.
Definition: LT_PMBus.cpp:1898
static void print_all_currents()
Print all currents.
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
static void loop()
Repeats Linduino loop.
static void margin_low()
Margin low.
static LT_PMBus * pmbus
Definition: hello_world.ino:84
static void setup()
Initialize Linduino.
Definition: hello_world.ino:88
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
float readVout(uint8_t address, bool polling)
Get the measured output voltage.
Definition: LT_PMBus.cpp:1598
#define LTC2977_I2C_ADDRESS
Definition: hello_world.ino:77
LT_I2CBus: Routines to communicate to I2C by Wire Library.
LTC PMBus Support: Implementation for a LTC Fault Log.
static void print_all_status()
Print all status bytes and words.
static void margin_off()
Go to nominal.
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
#define LTC2974_I2C_ADDRESS
Definition: hello_world.ino:76
void marginLowGlobal(void)
Margin all rails low.
Definition: LT_PMBus.cpp:3078
void sequenceOnGlobal(void)
Sequence on all rails.
Definition: LT_PMBus.cpp:2896
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
LTC SMBus Support: Implementation for a shared SMBus layer.
static void print_title()
Prints the title block when program first starts.
int32_t read_int()
void sequenceOffGlobal(void)
Sequence off all rails.
Definition: LT_PMBus.cpp:2876
void setVout(uint8_t address, float voltage)
Set output voltage.
Definition: LT_PMBus.cpp:239
static LT_SMBus * smbus
Definition: hello_world.ino:83
void executeGroupProtocol(void)
ends group protocol
Definition: LT_PMBus.cpp:3356
void restoreFromNvm(uint8_t address)
Restore device from NVM.
Definition: LT_PMBus.cpp:2663
static uint8_t ltc2974_i2c_address
Definition: hello_world.ino:81
LTC PMBus Support.
static float voltage
Definition: DC2289AA.ino:71
static uint16_t current
the current measurement from the LTC3335&#39;s counter test mode.
Definition: DC2343A.ino:114
static uint8_t ltc2977_i2c_address
Definition: hello_world.ino:82
static void print_prompt()
Prints main menu.
void marginHighGlobal(void)
Margin all rails high.
Definition: LT_PMBus.cpp:3068
LTC PMBus Support: Math conversion routines.
static void sequence_off_on()
Sequence off then on.
LTC SMBus Support: Implementation for a shared SMBus layer.
PMBus communication.
Definition: LT_PMBus.h:370