| 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();
92 ltc3880_i2c_address = LTC3880_I2C_ADDRESS;
93 ltc2974_i2c_address = LTC2974_I2C_ADDRESS;
94 ltc2977_i2c_address = LTC2977_I2C_ADDRESS;
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:
120 pmbus->enablePec(ltc3880_i2c_address);
121 pmbus->enablePec(ltc2974_i2c_address);
122 pmbus->enablePec(ltc2977_i2c_address);
123 delete smbus;
124 delete pmbus;
125 smbus = new LT_SMBusPec();
126 pmbus = new LT_PMBus(smbus);
127 break;
128 case 3:
129 pmbus->disablePec(ltc3880_i2c_address);
130 pmbus->disablePec(ltc2974_i2c_address);
131 pmbus->disablePec(ltc2977_i2c_address);
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);
148 pmbus->restoreFromNvm(ltc2974_i2c_address);
149 pmbus->restoreFromNvm(ltc2977_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
164 void print_title()
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
179 void print_prompt()
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
191 void print_warning_prompt()
192 {
193 Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
194 }
195
196 //! Print all voltages
197 //! @return void
198 void print_all_voltages()
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
231 void print_all_currents()
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
258 void print_all_status()
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);
269 b = pmbus->readStatusByte(ltc3880_i2c_address);
270 Serial.print(F("LTC3880 STATUS BYTE 0x"));
271 Serial.println(b, HEX);
272 w = pmbus->readStatusWord(ltc3880_i2c_address);
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);
282 b = pmbus->readStatusByte(ltc2974_i2c_address);
283 Serial.print(F("LTC2974 STATUS BYTE 0x"));
284 Serial.println(b, HEX);
285 w = pmbus->readStatusWord(ltc2974_i2c_address);
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);
295 b = pmbus->readStatusByte(ltc2977_i2c_address);
296 Serial.print(F("LTC2977 STATUS BYTE 0x"));
297 Serial.println(b, DEC);
298 w = pmbus->readStatusWord(ltc2977_i2c_address);
299 Serial.print(F("LTC2977 STATUS WORD 0x"));
300 Serial.println(w, HEX);
301 }
302 }
303
304 //! Sequence off then on
305 //! @return void
306 void sequence_off_on()
307 {
308 pmbus->sequenceOffGlobal();
309 delay (2000);
310 pmbus->sequenceOnGlobal();
311 }
312
313 //! Margin high
314 //! @return void
315 void margin_high()
316 {
317 pmbus->marginHighGlobal();
318 }
319
320 //! Margin low
321 //! @return void
322 void margin_low()
323 {
324 pmbus->marginLowGlobal();
325 }
326
327 //! Go to nominal
328 //! @return void
329 void margin_off()
330 {
331 pmbus->sequenceOnGlobal();
332 }
333
334 //! Display menu 1
335 void menu_1_basic_commands()
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:
365 print_all_voltages();
366 break;
367 case 2:
368 print_all_currents();
369 break;
370 case 3:
371 print_all_status();
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
margin_high
static void margin_high()
Margin high.
Definition: hello_world.ino:315
ltc3880_i2c_address
static uint8_t ltc3880_i2c_address
Definition: hello_world.ino:80
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
LT_SMBus.h
LTC SMBus Support: API for a shared SMBus layer.
LTC3880_I2C_ADDRESS
#define LTC3880_I2C_ADDRESS
Definition: hello_world.ino:75
LT_SMBusGroup.h
LTC SMBus Support: Implementation for a shared SMBus layer.
print_all_voltages
static void print_all_voltages()
Print all voltages.
Definition: hello_world.ino:198
LT_SMBusPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LT_PMBus::reset
void reset(uint8_t address)
Issue reset to one device.
Definition: LT_PMBus.cpp:2912
LT_PMBus::readStatusByte
uint8_t readStatusByte(uint8_t address)
Get the status byte.
Definition: LT_PMBus.cpp:2423
Linduino.h
Header File for Linduino Libraries and Demo Code.
menu_1_basic_commands
static void menu_1_basic_commands()
Display menu 1.
Definition: hello_world.ino:335
LT_PMBus::enablePec
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
LT_SMBusNoPec
Definition: LT_SMBusNoPec.h:60
LT_PMBus::readStatusWord
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
LT_PMBus::readIout
float readIout(uint8_t address, bool polling)
Get the measured output current.
Definition: LT_PMBus.cpp:1898
print_all_currents
static void print_all_currents()
Print all currents.
Definition: hello_world.ino:231
LT_PMBus::disablePec
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
loop
static void loop()
Repeats Linduino loop.
Definition: hello_world.ino:100
margin_low
static void margin_low()
Margin low.
Definition: hello_world.ino:322
pmbus
static LT_PMBus * pmbus
Definition: hello_world.ino:84
setup
static void setup()
Initialize Linduino.
Definition: hello_world.ino:88
LT_SMBusPec
Definition: LT_SMBusPec.h:61
LT_Wire.h
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
LT_SMBus
Definition: LT_SMBus.h:61
LT_PMBus::startGroupProtocol
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
LT_PMBus::readVout
float readVout(uint8_t address, bool polling)
Get the measured output voltage.
Definition: LT_PMBus.cpp:1598
LTC2977_I2C_ADDRESS
#define LTC2977_I2C_ADDRESS
Definition: hello_world.ino:77
LT_I2CBus.h
LT_I2CBus: Routines to communicate to I2C by Wire Library.
LT_FaultLog.h
LTC PMBus Support: Implementation for a LTC Fault Log.
print_all_status
static void print_all_status()
Print all status bytes and words.
Definition: hello_world.ino:258
margin_off
static void margin_off()
Go to nominal.
Definition: hello_world.ino:329
LT_PMBus::setPage
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
LTC2974_I2C_ADDRESS
#define LTC2974_I2C_ADDRESS
Definition: hello_world.ino:76
LT_PMBus::marginLowGlobal
void marginLowGlobal(void)
Margin all rails low.
Definition: LT_PMBus.cpp:3078
LT_PMBus::sequenceOnGlobal
void sequenceOnGlobal(void)
Sequence on all rails.
Definition: LT_PMBus.cpp:2896
LT_SMBus::probe
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
print_warning_prompt
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: hello_world.ino:191
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
print_title
static void print_title()
Prints the title block when program first starts.
Definition: hello_world.ino:164
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LT_PMBus::sequenceOffGlobal
void sequenceOffGlobal(void)
Sequence off all rails.
Definition: LT_PMBus.cpp:2876
LT_PMBus::setVout
void setVout(uint8_t address, float voltage)
Set output voltage.
Definition: LT_PMBus.cpp:239
smbus
static LT_SMBus * smbus
Definition: hello_world.ino:83
LT_PMBus::executeGroupProtocol
void executeGroupProtocol(void)
ends group protocol
Definition: LT_PMBus.cpp:3356
LT_PMBus::restoreFromNvm
void restoreFromNvm(uint8_t address)
Restore device from NVM.
Definition: LT_PMBus.cpp:2663
ltc2974_i2c_address
static uint8_t ltc2974_i2c_address
Definition: hello_world.ino:81
LT_PMBus.h
LTC PMBus Support.
voltage
static float voltage
Definition: DC2289AA.ino:71
current
static uint16_t current
the current measurement from the LTC3335&#39;s counter test mode.
Definition: DC2343A.ino:114
ltc2977_i2c_address
static uint8_t ltc2977_i2c_address
Definition: hello_world.ino:82
print_prompt
static void print_prompt()
Prints main menu.
Definition: hello_world.ino:179
LT_PMBus::marginHighGlobal
void marginHighGlobal(void)
Margin all rails high.
Definition: LT_PMBus.cpp:3068
LT_PMBusMath.h
LTC PMBus Support: Math conversion routines.
sequence_off_on
static void sequence_off_on()
Sequence off then on.
Definition: hello_world.ino:306
LT_SMBusBase.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370