104 const char ack_error[] =
"Error: No Acknowledge. Check I2C Address.";
112 Serial.begin(115200);
125 if (Serial.available())
128 if (user_command !=
'm')
129 Serial.println(user_command);
132 switch (user_command)
153 Serial.println(
"Incorrect Option");
158 Serial.print(F(
"*****************************************"));
167 Serial.println(F(
"\n*****************************************************************"));
168 Serial.print(F(
"* DC998A Demonstration Program *\n"));
169 Serial.print(F(
"* *\n"));
170 Serial.print(F(
"* This program demonstrates how to send and receive data from *\n"));
171 Serial.print(F(
"* the Negative Voltage Hot Swap Controllers *\n"));
172 Serial.print(F(
"* with ADC and I2C Monitoring *\n"));
173 Serial.print(F(
"* Set the baud rate to 115200 and select the newline terminator.*\n"));
174 Serial.print(F(
"* *\n"));
175 Serial.print(F(
"*****************************************************************\n"));
181 Serial.print(F(
"\n\nMain Menu\n"));
182 Serial.print(F(
" 1. Read current and voltage on continous mode\n"));
183 Serial.print(F(
" 2. Read and clear faults\n"));
184 Serial.print(F(
" 3. Request for alert response address (ARA)\n"));
185 Serial.print(F(
" 4. Manage alerts\n"));
186 Serial.print(F(
" 5. Settings\n"));
187 Serial.print(F(
" 6. Read all registers\n\n"));
188 Serial.print(F(
"Enter a command: "));
196 float current, adin_voltage, adin2_voltage;
197 uint16_t current_code, adin_code, adin2_code;
202 Serial.print(F(
"********** Press Enter to Exit ***********\n\n"));
206 Serial.println(F(
"Faults Detected :"));
208 Serial.println(F(
" EXTERNAL FAULT DETECTED"));
210 Serial.println(F(
" PGIO INPUT HIGH DETECTED"));
212 Serial.println(F(
" FET SHORT DETECTED"));
214 Serial.println(F(
" !EN STATE CHANGE DETECTED"));
216 Serial.println(F(
" BAD POWER DETECTED"));
218 Serial.println(F(
" OVERCURRENT DETECTED"));
220 Serial.println(F(
" UNDERVOLTAGE DETECTED"));
222 Serial.println(F(
" OVERVOLTAGE DETECTED"));
225 Serial.println(F(
" NO FAULTS DETECTED"));
235 Serial.print(F(
"\nCURRENT CODE: "));
236 Serial.println(current_code);
237 Serial.print(F(
"CURRENT CALCULATED: "));
238 Serial.println(current,4);
239 Serial.print(F(
"\nADIN CODE: "));
240 Serial.println(adin_code, HEX);
241 Serial.print(F(
"VOLTAGE CALCULATED BY ADIN: "));
242 Serial.println(adin_voltage,4);
243 Serial.print(F(
"\nADIN2 CODE: "));
244 Serial.println(adin2_code, HEX);
245 Serial.print(F(
"VOLTAGE CALCULATED BY ADIN2: "));
246 Serial.println(adin2_voltage,4);
250 while (Serial.available()==
false && ack== 0);
251 if (Serial.available())
266 Serial.println(F(
"Faults Detected :"));
268 Serial.println(F(
" EXTERNAL FAULT DETECTED"));
270 Serial.println(F(
" PGIO INPUT HIGH DETECTED"));
272 Serial.println(F(
" FET SHORT DETECTED"));
274 Serial.println(F(
" !EN STATE CHANGE DETECTED"));
276 Serial.println(F(
" BAD POWER DETECTED"));
278 Serial.println(F(
" OVERCURRENT DETECTED"));
280 Serial.println(F(
" UNDERVOLTAGE DETECTED"));
282 Serial.println(F(
" OVERVOLTAGE DETECTED"));
285 Serial.print(F(
" ALL FAULTS CLEARED \n\n"));
296 Serial.print(F(
" ALERT RESPONSE ADDRESS : 0x"));
297 Serial.println(address,HEX);
298 if (address == 0xFF && ack == 1)
301 Serial.print(F(
" NO RESPONSE\n\n"));
311 uint8_t alert_settings = 0;
315 Serial.println(F(
"EXTERNAL FAULT ALERT"));
316 Serial.println(F(
" 1. Enable"));
317 Serial.println(F(
" 2. Disable"));
318 Serial.print(F(
"Enter a command: "));
320 if (user_command ==
'm')
323 Serial.println(user_command);
325 if (user_command == 1)
327 else if (user_command ==2)
329 else if (user_command !=
'm')
330 Serial.println(
"Incorrect Option\n");
334 Serial.println(F(
"PGIO OUTPUT"));
335 Serial.println(F(
" 1. Enable"));
336 Serial.println(F(
" 2. Disable"));
337 Serial.print(F(
"Enter a command: "));
339 if (user_command ==
'm')
342 Serial.println(user_command);
344 if (user_command == 1)
346 else if (user_command ==2)
348 else if (user_command !=
'm')
349 Serial.println(
"Incorrect Option\n");
353 Serial.println(F(
"FET SHORT ALERT"));
354 Serial.println(F(
" 1. Enable"));
355 Serial.println(F(
" 2. Disable"));
356 Serial.print(F(
"Enter a command: "));
358 if (user_command ==
'm')
361 Serial.println(user_command);
363 if (user_command == 1)
365 else if (user_command ==2)
367 else if (user_command !=
'm')
368 Serial.println(
"Incorrect Option\n");
373 Serial.println(F(
"!EN STATE CHANGE ALERT"));
374 Serial.println(F(
" 1. Enable"));
375 Serial.println(F(
" 2. Disable"));
376 Serial.print(F(
"Enter a command: "));
378 if (user_command ==
'm')
381 Serial.println(user_command);
383 if (user_command == 1)
385 else if (user_command ==2)
387 else if (user_command !=
'm')
388 Serial.println(
"Incorrect Option\n");
392 Serial.println(F(
"POWER BAD ALERT"));
393 Serial.println(F(
" 1. Enable"));
394 Serial.println(F(
" 2. Disable"));
395 Serial.print(F(
"Enter a command: "));
397 if (user_command ==
'm')
400 Serial.println(user_command);
402 if (user_command == 1)
404 else if (user_command ==2)
406 else if (user_command !=
'm')
407 Serial.println(
"Incorrect Option\n");
411 Serial.println(F(
"OVERCURRENT ALERT"));
412 Serial.println(F(
" 1. Enable"));
413 Serial.println(F(
" 2. Disable"));
414 Serial.print(F(
"Enter a command: "));
416 if (user_command ==
'm')
419 Serial.println(user_command);
421 if (user_command == 1)
423 else if (user_command ==2)
425 else if (user_command !=
'm')
426 Serial.println(
"Incorrect Option\n");
430 Serial.println(F(
"UNDERVOLTAGE ALERT"));
431 Serial.println(F(
" 1. Enable"));
432 Serial.println(F(
" 2. Disable"));
433 Serial.print(F(
"Enter a command: "));
435 if (user_command ==
'm')
438 Serial.println(user_command);
440 if (user_command == 1)
442 else if (user_command ==2)
444 else if (user_command !=
'm')
445 Serial.println(
"Incorrect Option\n");
449 Serial.println(F(
"OVERVOLTAGE ALERT"));
450 Serial.println(F(
" 1. Enable"));
451 Serial.println(F(
" 2. Disable"));
452 Serial.print(F(
"Enter a command: "));
454 if (user_command ==
'm')
457 Serial.println(user_command);
459 if (user_command == 1)
461 else if (user_command ==2)
463 else if (user_command !=
'm')
464 Serial.println(
"Incorrect Option\n");
468 Serial.print(F(
"\n ALERTS UPDATED\n\n"));
469 Serial.println(F(
" m. Main Menu"));
470 Serial.println(F(
" 1. Repeat"));
471 Serial.print(F(
"Enter a command: "));
473 if (user_command ==
'm')
476 Serial.println(user_command);
479 while (!((user_command ==
'm') || (ack)));
493 Serial.println(F(
"PGIO"));
494 Serial.println(F(
" 1. !POWER GOOD"));
495 Serial.println(F(
" 2. POWER GOOD"));
496 Serial.println(F(
" 3. General Purpose Output"));
497 Serial.println(F(
" 4. General Purpose Input"));
498 Serial.print(F(
"Enter a command: "));
500 if (user_command ==
'm')
506 Serial.println(user_command);
508 switch (user_command)
523 if (user_command !=
'm')
524 Serial.println(
"Incorrect Option\n");
528 Serial.println(F(
"TEST MODE ENABLE"));
529 Serial.println(F(
" 1. Enable"));
530 Serial.println(F(
" 2. Disable"));
531 Serial.print(F(
"Enter a command: "));
533 if (user_command ==
'm')
536 Serial.println(user_command);
538 if (user_command == 1)
540 else if (user_command ==2)
542 else if (user_command !=
'm')
543 Serial.println(
"Incorrect Option\n");
547 Serial.println(F(
"POWER BAD AUTO RETRY"));
548 Serial.println(F(
" 1. Enable"));
549 Serial.println(F(
" 2. Disable"));
550 Serial.print(F(
"Enter a command: "));
552 if (user_command ==
'm')
555 Serial.println(user_command);
557 if (user_command == 1)
559 else if (user_command ==2)
561 else if (user_command !=
'm')
562 Serial.println(
"Incorrect Option\n");
567 Serial.println(F(
"FET STATUS"));
568 Serial.println(F(
" 1. ON"));
569 Serial.println(F(
" 2. OFF"));
570 Serial.print(F(
"Enter a command: "));
572 if (user_command ==
'm')
575 Serial.println(user_command);
577 if (user_command == 1)
579 else if (user_command ==2)
581 else if (user_command !=
'm')
582 Serial.println(
"Incorrect Option\n");
586 Serial.println(F(
"OVERCURRENT AUTO RETRY"));
587 Serial.println(F(
" 1. Enable"));
588 Serial.println(F(
" 2. Disable"));
589 Serial.print(F(
"Enter a command: "));
591 if (user_command ==
'm')
594 Serial.println(user_command);
596 if (user_command == 1)
598 else if (user_command ==2)
600 else if (user_command !=
'm')
601 Serial.println(
"Incorrect Option\n");
605 Serial.println(F(
"UNDERVOLTAGE AUTO RETRY"));
606 Serial.println(F(
" 1. Enable"));
607 Serial.println(F(
" 2. Disable"));
608 Serial.print(F(
"Enter a command: "));
610 if (user_command ==
'm')
613 Serial.println(user_command);
615 if (user_command == 1)
617 else if (user_command ==2)
619 else if (user_command !=
'm')
620 Serial.println(
"Incorrect Option\n");
625 Serial.println(F(
"OVERVOLTAGE AUTO RETRY"));
626 Serial.println(F(
" 1. Enable"));
627 Serial.println(F(
" 2. Disable"));
628 Serial.print(F(
"Enter a command: "));
630 if (user_command ==
'm')
633 Serial.println(user_command);
635 if (user_command == 1)
637 else if (user_command ==2)
639 else if (user_command !=
'm')
640 Serial.println(
"Incorrect Option\n");
644 Serial.print(F(
"\nSETTINGS UPDATED\n\n"));
645 Serial.println(F(
" m. Main Menu"));
646 Serial.println(F(
" 1. Repeat"));
647 Serial.print(F(
"Enter a command: "));
649 if (user_command ==
'm')
652 Serial.println(user_command);
655 while (!((user_command ==
'm') || (ack)));
666 Serial.print(
" FAULT REGISTER : 0b");
667 Serial.println(faults, BIN);
669 Serial.print(
" STATUS REGISTER : 0b");
670 Serial.println(faults, BIN);
672 Serial.print(
" ALERT REGISTER : 0b");
673 Serial.println(faults, BIN);
675 Serial.print(
" CONTROL REGISTER : 0b");
676 Serial.println(faults, BIN);
#define LTC4261_OVERVOLTAGE_FAULT
#define LTC4261_POWER_BAD_FAULT
#define LTC4261_TEST_MODE_ENABLE
#define LTC4261_POWER_BAD_DISABLE
#define LTC4261_TEST_MODE_DISABLE
#define LTC4261_EXTERNAL_FAULT_ENABLE
unsigned char user_command
#define LTC4261_PGIO_GENERAL_PURPOSE_OUTPUT
#define LTC4261_EXTERNAL_FAULT_DISABLE
static void setup()
Initialize Linduino.
int8_t LTC4261_write(uint8_t i2c_address, uint8_t command, uint8_t code)
Write an 8-bit code to the LTC4261.
static void loop()
Repeats Linduino loop.
#define LTC4261_OVERCURRENT_DISABLE
static int8_t main_menu_2_read_and_clear_faults()
Function to read and clear fault register.
#define LTC4261_PGIO_POWER_GOODX
#define LTC4261_ADIN2_MSB_REG
Header File for Linduino Libraries and Demo Code.
#define LTC4261_SENSE_MSB_REG
#define LTC4261_PGIO_OUTPUT_ENABLE
static int8_t demo_board_connected
Set to 1 if the board is connected.
const float resistive_ratio
LTC4261: Negative Voltage Hot Swap Controller with ADC and I2C Monitoring.
#define LTC4261_CONTROL_REG
int8_t LTC4261_read_10_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 10-bit adc_code from LTC4261.
#define LTC4261_UNDERVOLTAGE_AUTO_RETRY_ENABLE
#define LTC4261_POWER_BAD_ENABLE
#define LTC4261_STATUS_REG
static void print_title()
Print the title block.
int8_t LTC4261_ARA(uint8_t alert_response_address, uint8_t *i2c_address)
SMBus Alert Response Protocol: Sends an alert response command and releases /ALERT pin...
#define LTC4261_OVERVOLTAGE_ENABLE
int8_t LTC4261_read(uint8_t i2c_address, uint8_t command, uint8_t *code)
Reads an 8-bit adc_code from LTC4261.
#define LTC4261_EXTERNAL_FAULT
static void settings()
Configures the output.
#define LTC4261_UNDERVOLTAGE_FAULT
#define LTC4261_POWER_BAD_AUTO_RETRY_DISABLE
#define LTC4261_I2C_Address
#define LTC4261_OVERVOLTAGE_AUTO_RETRY_DISABLE
#define LTC4261_EN_STATE_DISABLE
#define LTC4261_FAULT_REG
#define LTC4261_PGIO_INPUT_HIGH
#define LTC4261_I2C_ALERT_RESPONSE
const char ack_error[]
Error message.
#define LTC4261_UNDERVOLTAGE_DISABLE
#define LTC4261_FET_SHORT_ENABLE
#define LTC4261_OVERCURRENT_ENABLE
#define LTC4261_PGIO_OUTPUT_DISABLE
#define LTC4261_PGIO_GENERAL_PURPOSE_INPUT
#define LTC4261_UNDERVOLTAGE_AUTO_RETRY_DISABLE
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
static int8_t main_menu_6_read_all_registers()
Function to read all registers.
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
#define LTC4261_PGIO_POWER_GOOD
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
#define LTC4261_UNDERVOLTAGE_ENABLE
#define LTC4261_POWER_BAD_AUTO_RETRY_ENABLE
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
static int8_t main_menu_1_continuous_mode()
Function to read Rsense current, ADIN voltage and ADIN2 voltage in continous mode.
#define LTC4261_EN_STATE_ENABLE
#define LTC4261_ALERT_REG
#define LTC4261_EN_STATE_CHANGE
#define LTC4261_FET_SHORT_FAULT
#define LTC4261_FET_SHORT_DISABLE
static void print_main_menu()
Print the main menu.
static int8_t main_menu_5_settings()
Function to update control register bits.
float LTC4261_code_to_current(uint16_t adc_code, float resistor, float LTC4261_DELTA_SENSE_lsb)
Calculate the LTC4261 current with a sense resistor.
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
#define LTC4261_OVERCURRENT_AUTO_RETRY_DISABLE
static uint16_t current
the current measurement from the LTC3335's counter test mode.
#define LTC4261_OVERCURRENT_FAULT
#define LTC4261_OVERCURRENT_AUTO_RETRY_ENABLE
float LTC4261_ADIN_code_to_voltage(uint16_t adc_code, float LTC4261_ADIN_lsb, float resistor_divider_ratio)
Calculate the LTC4261 ADIN voltage.
static int8_t main_menu_4_manage_alerts()
Function to update alert register bits.
static int8_t main_menu_3_send_ARA()
Function to send alert response (0001100) and read back the address of device that pulled ALERT pin l...
#define LTC4261_ADIN_MSB_REG
#define LTC4261_OVERVOLTAGE_AUTO_RETRY_ENABLE
#define LTC4261_OVERVOLTAGE_DISABLE