| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC2023A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1590B Demonstration Board
3 LTM2987: 16-Channel μModule PMBus Power System Manager
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/LTM2987
14
15 http://www.linear.com/demo/DC1590B
16
17
18 Copyright 2018(c) Analog Devices, Inc.
19
20 All rights reserved.
21
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions are met:
24 - Redistributions of source code must retain the above copyright
25 notice, this list of conditions and the following disclaimer.
26 - Redistributions in binary form must reproduce the above copyright
27 notice, this list of conditions and the following disclaimer in
28 the documentation and/or other materials provided with the
29 distribution.
30 - Neither the name of Analog Devices, Inc. nor the names of its
31 contributors may be used to endorse or promote products derived
32 from this software without specific prior written permission.
33 - The use of this software may or may not infringe the patent rights
34 of one or more patent holders. This license does not release you
35 from the requirement that you obtain separate licenses from these
36 patent holders to use this software.
37 - Use of the software either in source or binary form, must be run
38 on or directly connected to an Analog Devices Inc. component.
39
40 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
41 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
42 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
44 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
46 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 */
51
52 /*! @file
53 @ingroup LTM2987
54 */
55
56 #include <Arduino.h>
57 #include <stdint.h>
58 #include "Linduino.h"
59 #include "UserInterface.h"
60 #include "LT_I2CBus.h"
61 #include "LT_SMBusNoPec.h"
62 #include "LT_SMBusPec.h"
63 #include "LT_PMBus.h"
64
65 #define LTM2987_I2C_ADDRESS_1 0x30
66 #define LTM2987_I2C_ADDRESS_2 0x32
67
68 // Global variables
69 static uint8_t ltm2987_i2c_address_1;
70 static uint8_t ltm2987_i2c_address_2;
71 static LT_SMBus *smbus = new LT_SMBusPec();
72 static LT_PMBus *pmbus = new LT_PMBus(smbus);
73
74 //! Initialize Linduino
75 //! @return void
76 void setup()
77 {
78 Serial.begin(115200); //! Initialize the serial port to the PC
79 print_title();
80 ltm2987_i2c_address_1 = LTM2987_I2C_ADDRESS_1;
81 ltm2987_i2c_address_2 = LTM2987_I2C_ADDRESS_2;
82 print_prompt();
83 }
84
85 //! Repeats Linduino loop
86 //! @return void
87 void loop()
88 {
89 uint8_t user_command;
90 uint8_t res;
91 uint8_t model[7];
92 uint8_t *addresses = NULL;
93
94 if (Serial.available()) //! Checks for user input
95 {
96 user_command = read_int(); //! Reads the user command
97 if (user_command != 'm')
98 Serial.println(user_command);
99
100 switch (user_command) //! Prints the appropriate submenu
101 {
102 case 1:
103 menu_1_basic_commands(); // Print single-ended voltage menu
104 break;
105 case 2:
106 pmbus->enablePec(ltm2987_i2c_address_1);
107 pmbus->enablePec(ltm2987_i2c_address_2);
108 delete smbus;
109 delete pmbus;
110 smbus = new LT_SMBusPec();
111 pmbus = new LT_PMBus(smbus);
112 break;
113 case 3:
114 pmbus->disablePec(ltm2987_i2c_address_1);
115 pmbus->disablePec(ltm2987_i2c_address_2);
116 delete smbus;
117 delete pmbus;
118 smbus = new LT_SMBusNoPec();
119 pmbus = new LT_PMBus(smbus);
120 break;
121 case 4:
122 addresses = smbus->probe(0);
123 while (*addresses != 0)
124 {
125 Serial.print(F("ADDR 0x"));
126 Serial.println(*addresses++, HEX);
127 }
128 break;
129 case 5 :
130 pmbus->clearAllFaults(ltm2987_i2c_address_1);
131 pmbus->clearAllFaults(ltm2987_i2c_address_2);
132 break;
133 default:
134 Serial.println(F("Incorrect Option"));
135 break;
136 }
137 print_prompt();
138 }
139
140 }
141
142 // Function Definitions
143
144 //! Prints the title block when program first starts.
145 //! @return void
146 void print_title()
147 {
148 Serial.print(F("\n*****************************************************************\n"));
149 Serial.print(F("* DC2023A Demonstration Program *\n"));
150 Serial.print(F("* *\n"));
151 Serial.print(F("* This program demonstrates how to send and receive data from *\n"));
152 Serial.print(F("* the DC2023A demo board. *\n"));
153 Serial.print(F("* *\n"));
154 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
155 Serial.print(F("* *\n"));
156 Serial.print(F("*****************************************************************\n"));
157 }
158
159 //! Prints main menu.
160 //! @return void
161 void print_prompt()
162 {
163 Serial.print(F("\n 1-Basic Commands\n"));
164 Serial.print(F(" 2-PEC On\n"));
165 Serial.print(F(" 3-PEC Off\n"));
166 Serial.print(F(" 4-Bus Probe\n"));
167 Serial.print(F(" 5-Clear Faults\n"));
168 Serial.print(F("\nEnter a command:"));
169 }
170
171 //! Prints a warning if the demo board is not detected.
172 //! @return void
173 void print_warning_prompt()
174 {
175 Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
176 }
177
178 //! Print all voltages.
179 //! @return void
180 void print_all_voltages()
181 {
182 float voltage;
183 uint8_t page;
184
185 for (page = 0; page < 8; page++)
186 {
187 pmbus->setPage(ltm2987_i2c_address_1, page);
188 voltage = pmbus->readVout(ltm2987_i2c_address_1, false);
189 Serial.print(F("LTM2987 #1 VOUT "));
190 Serial.println(voltage, DEC);
191 }
192 for (page = 0; page < 8; page++)
193 {
194 pmbus->setPage(ltm2987_i2c_address_2, page);
195 voltage = pmbus->readVout(ltm2987_i2c_address_2, false);
196 Serial.print(F("LTM2987 #2 VOUT "));
197 Serial.println(voltage, DEC);
198 }
199 }
200
201 //! Print all status bytes and words.
202 //! @return void
203 void print_all_status()
204 {
205 uint8_t b;
206 uint16_t w;
207 uint8_t page;
208
209 for (page = 0; page < 8; page++)
210 {
211 Serial.print(F("PAGE "));
212 Serial.println(page, DEC);
213 pmbus->setPage(ltm2987_i2c_address_1, page);
214 b = pmbus->readStatusByte(ltm2987_i2c_address_1);
215 Serial.print(F("LTM2987 #1 STATUS BYTE 0x"));
216 Serial.println(b, HEX);
217 w = pmbus->readStatusWord(ltm2987_i2c_address_1);
218 Serial.print(F("LTM2987 #1 STATUS WORD 0x"));
219 Serial.println(w, HEX);
220 }
221
222 for (page = 0; page < 8; page++)
223 {
224 Serial.print(F("PAGE "));
225 Serial.println(page, DEC);
226 pmbus->setPage(ltm2987_i2c_address_2, page);
227 b = pmbus->readStatusByte(ltm2987_i2c_address_2);
228 Serial.print(F("LTM2982 #2 STATUS BYTE 0x"));
229 Serial.println(b, HEX);
230 w = pmbus->readStatusWord(ltm2987_i2c_address_2);
231 Serial.print(F("LTM2987 #2 STATUS WORD 0x"));
232 Serial.println(w, HEX);
233 }
234 }
235
236 //! Sequence off then on
237 //! @return void
238 void sequence_off_on()
239 {
240 pmbus->sequenceOffGlobal();
241 delay (2000);
242 pmbus->sequenceOnGlobal();
243 }
244
245 //! Margin high
246 //! @return void
247 void margin_high()
248 {
249 pmbus->marginHighGlobal();
250 }
251
252 //! Margin low
253 //! @return void
254 void margin_low()
255 {
256 pmbus->marginLowGlobal();
257 }
258
259 //! Go to nominal
260 //! @return void
261 void margin_off()
262 {
263 pmbus->sequenceOnGlobal();
264 }
265
266 //! Display menu 1
267 //! @return void
268 void menu_1_basic_commands()
269 {
270 uint8_t user_command;
271
272 do
273 {
274 //! Displays the Read/Write menu
275 Serial.print(F("\nRead/Write\n\n"));
276 Serial.print(F(" 1-Read All Voltages\n"));
277 Serial.print(F(" 2-Read All Status\n"));
278 Serial.print(F(" 3-Sequence Off/On\n"));
279 Serial.print(F(" 4-Margin High\n"));
280 Serial.print(F(" 5-Margin Low\n"));
281 Serial.print(F(" 6-Margin Off\n"));
282 Serial.print(F(" m-Main Menu\n"));
283 Serial.print(F("\nEnter a command: "));
284
285 user_command = read_int(); //! Reads the user command
286 if (user_command == 'm') // Print m if it is entered
287 {
288 Serial.print(F("m\n"));
289 }
290 else
291 Serial.println(user_command); // Print user command
292
293 switch (user_command)
294 {
295 case 1:
296 print_all_voltages();
297 break;
298 case 2:
299 print_all_status();
300 break;
301 case 3:
302 sequence_off_on();
303 break;
304 case 4:
305 margin_high();
306 break;
307 case 5:
308 margin_low();
309 break;
310 case 6:
311 margin_off();
312 break;
313 default:
314 if (user_command != 'm')
315 Serial.println(F("Invalid Selection"));
316 break;
317 }
318 }
319 while (user_command != 'm');
320 }
321
322
ltm2987_i2c_address_2
static uint8_t ltm2987_i2c_address_2
Definition: DC2023A.ino:70
ltm2987_i2c_address_1
static uint8_t ltm2987_i2c_address_1
Definition: DC2023A.ino:69
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
setup
static void setup()
Initialize Linduino.
Definition: DC2023A.ino:76
LT_SMBusPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
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.
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
print_all_voltages
static void print_all_voltages()
Print all voltages.
Definition: DC2023A.ino:180
LT_PMBus::readStatusWord
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
smbus
static LT_SMBus * smbus
Definition: DC2023A.ino:71
LT_PMBus::disablePec
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
LTM2987_I2C_ADDRESS_1
#define LTM2987_I2C_ADDRESS_1
Definition: DC2023A.ino:65
print_all_status
static void print_all_status()
Print all status bytes and words.
Definition: DC2023A.ino:203
LT_SMBusPec
Definition: LT_SMBusPec.h:61
loop
static void loop()
Repeats Linduino loop.
Definition: DC2023A.ino:87
LT_SMBus
Definition: LT_SMBus.h:61
margin_high
static void margin_high()
Margin high.
Definition: DC2023A.ino:247
LT_PMBus::readVout
float readVout(uint8_t address, bool polling)
Get the measured output voltage.
Definition: LT_PMBus.cpp:1598
sequence_off_on
static void sequence_off_on()
Sequence off then on.
Definition: DC2023A.ino:238
LT_I2CBus.h
LT_I2CBus: Routines to communicate to I2C by Wire Library.
LT_PMBus::setPage
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
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_PMBus::clearAllFaults
void clearAllFaults(uint8_t address)
Clear all the faults for all pages.
Definition: LT_PMBus.cpp:2576
LT_SMBus::probe
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
menu_1_basic_commands
static void menu_1_basic_commands()
Display menu 1.
Definition: DC2023A.ino:268
LT_PMBus::sequenceOffGlobal
void sequenceOffGlobal(void)
Sequence off all rails.
Definition: LT_PMBus.cpp:2876
LTM2987_I2C_ADDRESS_2
#define LTM2987_I2C_ADDRESS_2
Definition: DC2023A.ino:66
print_warning_prompt
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: DC2023A.ino:173
LT_PMBus.h
LTC PMBus Support.
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC2023A.ino:146
margin_off
static void margin_off()
Go to nominal.
Definition: DC2023A.ino:261
voltage
static float voltage
Definition: DC2289AA.ino:71
LT_PMBus::marginHighGlobal
void marginHighGlobal(void)
Margin all rails high.
Definition: LT_PMBus.cpp:3068
pmbus
static LT_PMBus * pmbus
Definition: DC2023A.ino:72
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC2023A.ino:161
margin_low
static void margin_low()
Margin low.
Definition: DC2023A.ino:254
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370