86 #define SENSE_RESISTOR 0.004 103 Serial.begin(115200);
115 if (Serial.available())
118 if (user_command !=
'm')
119 Serial.println(user_command);
122 switch (user_command)
143 Serial.println(
"Incorrect Option");
155 Serial.println(F(
"\n*****************************************************************"));
156 Serial.print(F(
"* DC874A Demonstration Program *\n"));
157 Serial.print(F(
"* *\n"));
158 Serial.print(F(
"* This program demonstrates how to send and receive data from *\n"));
159 Serial.print(F(
"* LTC4280 Hot Swap Controller with I2C Compatible Monitoring *\n"));
160 Serial.print(F(
"* Set the baud rate to 115200 and select the newline terminator.*\n"));
161 Serial.print(F(
"* *\n"));
162 Serial.print(F(
"*****************************************************************\n"));
168 Serial.print(F(
"\n\nMain Menu\n"));
169 Serial.print(F(
" 1. Read current and voltage on continous mode\n"));
170 Serial.print(F(
" 2. Read and clear faults\n"));
171 Serial.print(F(
" 3. Request for alert response address (ARA)\n"));
172 Serial.print(F(
" 4. Manage alerts\n"));
173 Serial.print(F(
" 5. Settings\n"));
174 Serial.print(F(
" 6. Read all registers\n\n"));
175 Serial.print(F(
"Enter a command: "));
183 float sense_voltage, source_voltage, adin_voltage;
184 uint8_t sense_code, source_code, adin_code;
185 float adin_lsb = (1.23/255), adin_resisive_ratio = (155.4/12.4);
186 float source_lsb = (15.44/255), source_resisive_ratio = 1;
187 float sense_lsb = (0.03845/255), sense_resisive_ratio = 1;
192 Serial.print(F(
"********** Press Enter to Exit ***********\n\n"));
196 Serial.println(F(
"Faults Detected :"));
198 Serial.println(F(
" FET SHORT DETECTED"));
200 Serial.println(F(
" !EN STATE CHANGE DETECTED"));
202 Serial.println(F(
" BAD POWER DETECTED"));
204 Serial.println(F(
" OVERCURRENT DETECTED"));
206 Serial.println(F(
" UNDERVOLTAGE DETECTED"));
208 Serial.println(F(
" OVERVOLTAGE DETECTED"));
211 Serial.println(F(
" NO FAULTS DETECTED"));
221 Serial.print(F(
"\nSENSE VOLTAGE CODE: "));
222 Serial.println(sense_code, HEX);
223 Serial.print(F(
"SENSE CURRENT CALCULATED: "));
225 Serial.print(F(
"\nSOURCE VOLTAGE CODE: "));
226 Serial.println(source_code, HEX);
227 Serial.print(F(
"SOURCE VOLTAGE CALCULATED: "));
228 Serial.println(source_voltage, 4);
229 Serial.print(F(
"\nADIN CODE: "));
230 Serial.println(adin_code, HEX);
231 Serial.print(F(
"VOLTAGE CALCULATED AT ADIN: "));
232 Serial.println(adin_voltage, 4);
236 while (Serial.available()==
false && ack== 0);
237 if (Serial.available())
252 Serial.println(F(
"Faults Detected :"));
254 Serial.println(F(
" FET SHORT DETECTED"));
256 Serial.println(F(
" !EN STATE CHANGE DETECTED"));
258 Serial.println(F(
" BAD POWER DETECTED"));
260 Serial.println(F(
" OVERCURRENT DETECTED"));
262 Serial.println(F(
" UNDERVOLTAGE DETECTED"));
264 Serial.println(F(
" OVERVOLTAGE DETECTED"));
267 Serial.print(F(
"\nALL FAULTS CLEARED \n\n"));
279 Serial.print(F(
" ALERT RESPONSE ADDRESS : 0x"));
280 Serial.println(address,HEX);
281 if (address == 0xFF && ack == 1)
284 Serial.print(F(
" NO RESPONSE\n\n"));
294 uint8_t alert_settings = 0;
298 Serial.println(F(
"GPIO OUTPUT"));
299 Serial.println(F(
" 1. Enable"));
300 Serial.println(F(
" 2. Disable"));
301 Serial.print(F(
"Enter a command: "));
303 if (user_command ==
'm')
306 Serial.println(user_command);
308 if (user_command == 1)
310 else if (user_command ==2)
312 else if (user_command !=
'm')
313 Serial.println(
"Incorrect Option\n");
317 Serial.println(F(
"FET SHORT ALERT"));
318 Serial.println(F(
" 1. Enable"));
319 Serial.println(F(
" 2. Disable"));
320 Serial.print(F(
"Enter a command: "));
322 if (user_command ==
'm')
325 Serial.println(user_command);
327 if (user_command == 1)
329 else if (user_command ==2)
331 else if (user_command !=
'm')
332 Serial.println(
"Incorrect Option\n");
336 Serial.println(F(
"!EN STATE CHANGE ALERT"));
337 Serial.println(F(
" 1. Enable"));
338 Serial.println(F(
" 2. Disable"));
339 Serial.print(F(
"Enter a command: "));
341 if (user_command ==
'm')
344 Serial.println(user_command);
346 if (user_command == 1)
348 else if (user_command ==2)
350 else if (user_command !=
'm')
351 Serial.println(
"Incorrect Option\n");
355 Serial.println(F(
"POWER BAD ALERT"));
356 Serial.println(F(
" 1. Enable"));
357 Serial.println(F(
" 2. Disable"));
358 Serial.print(F(
"Enter a command: "));
360 if (user_command ==
'm')
363 Serial.println(user_command);
365 if (user_command == 1)
367 else if (user_command ==2)
369 else if (user_command !=
'm')
370 Serial.println(
"Incorrect Option\n");
374 Serial.println(F(
"OVERCURRENT ALERT"));
375 Serial.println(F(
" 1. Enable"));
376 Serial.println(F(
" 2. Disable"));
377 Serial.print(F(
"Enter a command: "));
379 if (user_command ==
'm')
382 Serial.println(user_command);
384 if (user_command == 1)
386 else if (user_command ==2)
388 else if (user_command !=
'm')
389 Serial.println(
"Incorrect Option\n");
393 Serial.println(F(
"UNDERVOLTAGE ALERT"));
394 Serial.println(F(
" 1. Enable"));
395 Serial.println(F(
" 2. Disable"));
396 Serial.print(F(
"Enter a command: "));
398 if (user_command ==
'm')
401 Serial.println(user_command);
403 if (user_command == 1)
405 else if (user_command ==2)
407 else if (user_command !=
'm')
408 Serial.println(
"Incorrect Option\n");
412 Serial.println(F(
"OVERVOLTAGE ALERT"));
413 Serial.println(F(
" 1. Enable"));
414 Serial.println(F(
" 2. Disable"));
415 Serial.print(F(
"Enter a command: "));
417 if (user_command ==
'm')
420 Serial.println(user_command);
422 if (user_command == 1)
424 else if (user_command ==2)
426 else if (user_command !=
'm')
427 Serial.println(
"Incorrect Option\n");
431 Serial.print(F(
"\n ALERTS UPDATED\n\n"));
432 Serial.println(F(
" m. Main Menu"));
433 Serial.println(F(
" 1. Repeat"));
434 Serial.print(F(
"Enter a command: "));
436 if (user_command ==
'm')
439 Serial.println(user_command);
442 while (!((user_command ==
'm') || (ack)));
455 Serial.println(F(
"PGIO"));
456 Serial.println(F(
" 1. !POWER GOOD"));
457 Serial.println(F(
" 2. POWER GOOD"));
458 Serial.println(F(
" 3. General Purpose Output"));
459 Serial.println(F(
" 4. General Purpose Input"));
460 Serial.print(F(
"Enter a command: "));
462 if (user_command ==
'm')
468 Serial.println(user_command);
470 switch (user_command)
485 if (user_command !=
'm')
486 Serial.println(
"Incorrect Option\n");
490 Serial.println(F(
"TEST MODE ENABLE"));
491 Serial.println(F(
" 1. Enable"));
492 Serial.println(F(
" 2. Disable"));
493 Serial.print(F(
"Enter a command: "));
495 if (user_command ==
'm')
498 Serial.println(user_command);
500 if (user_command == 1)
502 else if (user_command ==2)
504 else if (user_command !=
'm')
505 Serial.println(
"Incorrect Option\n");
509 Serial.println(F(
"MASS WRITE ENABLE"));
510 Serial.println(F(
" 1. Enable"));
511 Serial.println(F(
" 2. Disable"));
512 Serial.print(F(
"Enter a command: "));
514 if (user_command ==
'm')
517 Serial.println(user_command);
519 if (user_command == 1)
521 else if (user_command ==2)
523 else if (user_command !=
'm')
524 Serial.println(
"Incorrect Option\n");
528 Serial.println(F(
"FET STATUS"));
529 Serial.println(F(
" 1. ON"));
530 Serial.println(F(
" 2. OFF"));
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(
"OVERCURRENT 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");
566 Serial.println(F(
"UNDERVOLTAGE AUTO RETRY"));
567 Serial.println(F(
" 1. Enable"));
568 Serial.println(F(
" 2. Disable"));
569 Serial.print(F(
"Enter a command: "));
571 if (user_command ==
'm')
574 Serial.println(user_command);
576 if (user_command == 1)
578 else if (user_command ==2)
580 else if (user_command !=
'm')
581 Serial.println(
"Incorrect Option\n");
585 Serial.println(F(
"OVERVOLTAGE AUTO RETRY"));
586 Serial.println(F(
" 1. Enable"));
587 Serial.println(F(
" 2. Disable"));
588 Serial.print(F(
"Enter a command: "));
590 if (user_command ==
'm')
593 Serial.println(user_command);
595 if (user_command == 1)
597 else if (user_command ==2)
599 else if (user_command !=
'm')
600 Serial.println(
"Incorrect Option\n");
604 Serial.print(F(
"\nSETTINGS UPDATED\n\n"));
605 Serial.println(F(
" m. Main Menu"));
606 Serial.println(F(
" 1. Repeat"));
607 Serial.print(F(
"Enter a command: "));
609 if (user_command ==
'm')
612 Serial.println(user_command);
615 while (!((user_command ==
'm') || (ack)));
626 Serial.print(
" FAULT REGISTER : 0b");
627 Serial.println(faults, BIN);
629 Serial.print(
" STATUS REGISTER : 0b");
630 Serial.println(faults, BIN);
632 Serial.print(
" ALERT REGISTER : 0b");
633 Serial.println(faults, BIN);
635 Serial.print(
" CONTROL REGISTER : 0b");
636 Serial.println(faults, BIN);
#define LTC4280_POWER_BAD_FAULT
#define LTC4280_TEST_MODE_DISABLE
static int8_t main_menu_4_manage_alerts()
Function to update alert register bits.
#define LTC4280_SOURCE_REG
static void print_title()
Print the title block.
unsigned char user_command
#define LTC4280_EN_STATE_DISABLE
#define LTC4280_UNDERVOLTAGE_ENABLE
float LTC4280_code_to_voltage(uint8_t register_code, float LSB, float resistor_divider_ratio)
Calculates voltage from register code data.
#define LTC4280_OVERCURRENT_DISABLE
#define LTC4280_OVERVOLTAGE_DISABLE
#define LTC4280_FET_SHORT_DISABLE
#define LTC4280_EN_STATE_CHANGE
#define LTC4280_TEST_MODE_ENABLE
#define LTC4280_GPIO_OUTPUT_ENABLE
#define LTC4280_STATUS_REG
#define LTC4280_PGIO_GENERAL_PURPOSE_OUTPUT
#define LTC4280_POWER_BAD_DISABLE
#define LTC4280_EN_STATE_ENABLE
#define LTC4280_GPIO_OUTPUT_DISABLE
#define LTC4280_UNDERVOLTAGE_AUTO_RETRY_ENABLE
#define LTC4280_OVERVOLTAGE_FAULT
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 LTC4280_ALERT_REG
#define LTC4280_UNDERVOLTAGE_DISABLE
static void loop()
Repeats Linduino loop.
#define LTC4280_CONTROL_REG
static void settings()
Configures the output.
#define LTC4280_OVERVOLTAGE_AUTO_RETRY_ENABLE
int8_t LTC4280_ARA(uint8_t alert_response_address, uint8_t *i2c_address)
SMBus Alert ResponseProtocol: Sends an alert response command and releases /ALERT pin...
#define LTC4280_OVERCURRENT_AUTO_RETRY_DISABLE
#define LTC4280_FET_SHORT_FAULT
int8_t LTC4280_write(uint8_t i2c_address, uint8_t command, uint8_t code)
Write an 8-bit code to the LTC4280.
static int8_t main_menu_1_continuous_mode()
Function to read Rsense current, ADIN voltage and ADIN2 voltage in continous mode.
#define LTC4280_I2C_ADDRESS
#define LTC4280_OVERVOLTAGE_ENABLE
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
#define LTC4280_FET_SHORT_ENABLE
#define LTC4280_OVERCURRENT_FAULT
#define LTC4280_POWER_BAD_ENABLE
static int8_t main_menu_5_settings()
Function to update control register bits.
#define LTC4280_SENSE_REG
static void print_prompt()
Print the main menu.
#define LTC4280_OVERCURRENT_AUTO_RETRY_ENABLE
#define LTC4280_I2C_ALERT_RESPONSE
#define LTC4280_OVERVOLTAGE_AUTO_RETRY_DISABLE
#define LTC4280_MASS_WRITE_ENABLE
#define LTC4280_PGIO_POWER_GOOD
#define LTC4280_UNDERVOLTAGE_AUTO_RETRY_DISABLE
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
LTC4280: Hot Swap Controller with I2C Compatible Monitoring.
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
#define LTC4280_MASS_WRITE_DISABLE
static void setup()
Initialize Linduino.
#define LTC4280_FAULT_REG
#define LTC4280_UNDERVOLTAGE_FAULT
static int8_t main_menu_2_read_and_clear_faults()
Function to read and clear fault register.
#define LTC4280_OVERCURRENT_ENABLE
int8_t LTC4280_read(uint8_t i2c_address, uint8_t command, uint8_t *code)
Reads an 8-bit adc_code from LTC4280.
#define LTC4280_PGIO_POWER_GOODX
static int8_t main_menu_6_read_all_registers()
Function to read all registers.
#define LTC4280_PGIO_GENERAL_PURPOSE_INPUT