![](/media/cache/profiles/6MiCIB0C_400x400.jpg.50x50_q85.jpg)
ADT74xx temperature sensor evaluation firmware.
Dependencies: platform_drivers ADT73xx-ADT74xx
Revision 5:f92081816fb7, committed 2019-11-27
- Comitter:
- ssmith73
- Date:
- Wed Nov 27 11:35:54 2019 +0000
- Parent:
- 4:b8f309710211
- Commit message:
- Updated line-endings on printf statements - different serial terminals highlighted formatting issues.
Changed in this revision
app_config.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b8f309710211 -r f92081816fb7 app_config.h --- a/app_config.h Mon Nov 04 17:01:16 2019 +0000 +++ b/app_config.h Wed Nov 27 11:35:54 2019 +0000 @@ -85,6 +85,11 @@ #define INTERNAL_SPI 0 /** + Add a line-ending constant as different emulators + implement it in various ways - simple to change it here +*/ +#define EOL "\r\n" +/** The ADI SDP_K1 can be used with both arduino headers or the 120-pin SDP connector found on ADI evaluation boards. The default is the SDP connector @@ -92,7 +97,7 @@ Uncomment the ARDUINO #define above to enable the ARDUINO connector */ -#define ARDUINO +//#define ARDUINO #ifdef ARDUINO #define I2C_SCL D15
diff -r b8f309710211 -r f92081816fb7 main.cpp --- a/main.cpp Mon Nov 04 17:01:16 2019 +0000 +++ b/main.cpp Wed Nov 27 11:35:54 2019 +0000 @@ -150,12 +150,12 @@ connected = adt7420_init(&device, init_params); if (connected != SUCCESS) { - pc.printf("\n\n Connection to device failed :(\n"); - pc.printf(" ...Restarting application... \n\n"); + pc.printf(EOL EOL " Connection to device failed :(" EOL); + pc.printf(" ...Restarting application... " EOL); wait(WAIT_MENU_TIME); microcontroller_reset(); } else { - pc.printf("\n\n Connection to device succeeded!\n"); + pc.printf(EOL EOL " Connection to device succeeded!" EOL); } while (connected == SUCCESS) { @@ -164,7 +164,7 @@ print_prompt(); if (get_menu_select(&menu_select) == FAILURE) - pc.printf("\n***** Returning to main menu *****\n"); + pc.printf(EOL "***** Returning to main menu *****" EOL); else { switch (menu_select) { case 1: @@ -200,7 +200,7 @@ microcontroller_reset(); break; default: - pc.printf("Invalid option"); + pc.printf("Invalid option" EOL); break; } } @@ -214,15 +214,15 @@ *******************************************************************************/ void print_title() { - pc.printf("*****************************************************************\n"); - pc.printf("* EVAL-TempeSense-ARDZ Demonstration Program -- (mbed) *\n"); - pc.printf("* *\n"); - pc.printf("* This program demonstrates communication with the ADT7xx *\n"); - pc.printf("* High-Accuracy digital temperature sensor family *\n"); - pc.printf("* It will also work with both SPI & I2C versions *\n"); - pc.printf("* *\n"); - pc.printf("* Set the baud rate to 115200 select the newline terminator. *\n"); - pc.printf("*****************************************************************\n"); + pc.printf("*****************************************************************" EOL); + pc.printf("* EVAL-TempeSense-ARDZ Demonstration Program -- (mbed) *" EOL); + pc.printf("* *" EOL); + pc.printf("* This program demonstrates communication with the ADT7xx *" EOL); + pc.printf("* High-Accuracy digital temperature sensor family *" EOL); + pc.printf("* It will also work with both SPI & I2C versions *" EOL); + pc.printf("* *" EOL); + pc.printf("* Set the baud rate to 115200 select the newline terminator. *" EOL); + pc.printf("*****************************************************************" EOL); } /***************************************************************************//** @@ -230,18 +230,18 @@ *******************************************************************************/ void print_prompt() { - pc.printf("\n\nCommand Summary:\n\n"); - pc.printf(" 1 -Read temperature\n"); - pc.printf(" 2 -Set resolution\n"); - pc.printf(" 3 -Set operation mode\n"); - pc.printf(" 4 -Poll temperature\n"); - pc.printf(" 5 -Read a register\n"); - pc.printf(" 6 -Reset the interface\n"); - pc.printf(" 7 -Write to a setpoint register\n"); - pc.printf(" 8 -Set Fault Queue configuration\n"); - pc.printf(" 9 -Set CT/INT polarity and mode\n"); - pc.printf(" 10 -Full System Reset\n"); - pc.printf("\n"); + pc.printf(EOL EOL "Command Summary:" EOL); + pc.printf(" 1 -Read temperature" EOL); + pc.printf(" 2 -Set resolution" EOL); + pc.printf(" 3 -Set operation mode" EOL); + pc.printf(" 4 -Poll temperature" EOL); + pc.printf(" 5 -Read a register" EOL); + pc.printf(" 6 -Reset the interface" EOL); + pc.printf(" 7 -Write to a setpoint register" EOL); + pc.printf(" 8 -Set Fault Queue configuration" EOL); + pc.printf(" 9 -Set CT/INT polarity and mode" EOL); + pc.printf(" 10 -Full System Reset" EOL); + pc.printf(EOL); } static int get_menu_select(uint8_t *menu_select) @@ -265,9 +265,9 @@ *******************************************************************************/ uint8_t select_device() { - pc.printf("Please select interface by choosing a device:\n"); - pc.printf(" 1- ADT7320 (SPI)\n"); - pc.printf(" 2- ADT7420 (I2C)\n"); + pc.printf("Please select interface by choosing a device:" EOL); + pc.printf(" 1- ADT7320 (SPI)" EOL); + pc.printf(" 2- ADT7420 (I2C)" EOL); pc.printf(" Select an option: "); int invalid_check, new_interface = 0; @@ -275,9 +275,9 @@ //Prompts for user input while correct interface is not selected while (input_check(new_interface, 1, 2, invalid_check) == FAILURE) { - pc.printf("Please select interface by choosing a device:\n"); - pc.printf(" 1- ADT7320 (SPI)\n"); - pc.printf(" 2- ADT7420 (I2C)\n"); + pc.printf("Please select interface by choosing a device:" EOL); + pc.printf(" 1- ADT7320 (SPI)" EOL); + pc.printf(" 2- ADT7420 (I2C)" EOL); pc.printf(" Select an option: "); invalid_check = pc.scanf("%d", &new_interface); } @@ -285,18 +285,18 @@ switch (new_interface) { case 1: - pc.printf(" ADT7320 sensor selected!\n\n"); + pc.printf(" ADT7320 sensor selected!" EOL EOL); init_params.act_device = ID_ADT7320; break; case 2: - pc.printf(" ADT7420 sensor selected!\n\n"); + pc.printf(" ADT7420 sensor selected!" EOL EOL); init_params.act_device = ID_ADT7420; break; } - pc.printf("Available devices:\n"); - pc.printf(" 1- Internal (Main PCB)\n"); - pc.printf(" 2- Remote (External PCB)\n"); + pc.printf("Available devices:" EOL); + pc.printf(" 1- Internal (Main PCB)" EOL); + pc.printf(" 2- Remote (External PCB)" EOL); pc.printf(" Select an option: "); int new_dev = 0; @@ -304,9 +304,9 @@ //Prompts for user input while correct device is not selected while (input_check(new_dev, 1, 2, invalid_check) == FAILURE) { - pc.printf("Device select:\n"); - pc.printf(" 1- Internal (Main PCB)\n"); - pc.printf(" 2- Remote (External PCB)\n"); + pc.printf("Device select:" EOL); + pc.printf(" 1- Internal (Main PCB)" EOL); + pc.printf(" 2- Remote (External PCB)" EOL); pc.printf(" Select an option: "); invalid_check = pc.scanf("%d", &new_dev); } @@ -353,9 +353,9 @@ *******************************************************************************/ static uint8_t set_resolution() { - pc.printf(" Available resolutions:\n"); - pc.printf(" 1- 13-bit\n"); - pc.printf(" 2- 16-bit\n"); + pc.printf(" Available resolutions:" EOL); + pc.printf(" 1- 13-bit" EOL); + pc.printf(" 2- 16-bit" EOL); pc.printf(" Select an option: "); int new_res, invalid_check = 0; @@ -364,7 +364,7 @@ if (input_check(new_res, 1, 2, invalid_check) == FAILURE) { return FAILURE; } else { - pc.printf("%d\n", new_res); + pc.printf("%d" EOL, new_res); new_res = (new_res == 1) ? 0 : 1; adt7420_set_resolution(device, new_res); pc.printf("Set resolution to %d-bit", (13 + 3 * new_res)); @@ -383,11 +383,11 @@ *******************************************************************************/ static uint8_t set_op_mode() { - pc.printf(" Available operation modes:\n"); - pc.printf(" 1- Continuous conversion mode (default)\n"); - pc.printf(" 2- One-shot mode\n"); - pc.printf(" 3- 1 SPS mode\n"); - pc.printf(" 4- Shutdown\n"); + pc.printf(" Available operation modes:" EOL); + pc.printf(" 1- Continuous conversion mode (default)" EOL); + pc.printf(" 2- One-shot mode" EOL); + pc.printf(" 3- 1 SPS mode" EOL); + pc.printf(" 4- Shutdown" EOL); pc.printf(" Select a mode: "); int new_mode, invalid_check = 0; @@ -395,7 +395,7 @@ if (input_check(new_mode, 1, 4, invalid_check) == FAILURE) { return FAILURE; } else { - pc.printf("%d\n", new_mode); + pc.printf("%d" EOL, new_mode); switch (new_mode) { case 1: adt7420_set_operation_mode(device, ADT7420_OP_MODE_CONT_CONV); @@ -403,8 +403,8 @@ case 2: /*When One shot mode is set completes one conversion and immediately goes to shutdown mode*/ adt7420_set_operation_mode(device, ADT7420_OP_MODE_ONE_SHOT); - pc.printf("\n One Shot mode enabled, device will enter shutdown mode once a conversion is complete.\n"); - pc.printf(" See page 10 in datasheet for details.\n"); + pc.printf( EOL" One Shot mode enabled, device will enter shutdown mode once a conversion is complete." EOL); + pc.printf(" See page 10 in datasheet for details." EOL); break; case 3: adt7420_set_operation_mode(device, ADT7420_OP_MODE_1_SPS); @@ -413,7 +413,7 @@ adt7420_set_operation_mode(device, ADT7420_OP_MODE_SHUTDOWN); break; default: - pc.printf("Invalid option\n"); + pc.printf("Invalid option" EOL); break; } return SUCCESS; @@ -438,7 +438,7 @@ if (input_check(num_samples, 1, 2000000, invalid_check) == FAILURE) { return FAILURE; } - pc.printf("%d\n", num_samples); + pc.printf("%d" EOL, num_samples); pc.printf(" Enter a desired frequency in samples/sec (max 10): "); int sample_freq = 1; @@ -451,8 +451,8 @@ uint32_t delay_sec = 1000000 / sample_freq; - pc.printf(" Gathering %d seconds of samples\n", num_samples/sample_freq); - pc.printf("Press enter to continue and then press again to quit\n"); + pc.printf(" Gathering %d seconds of samples" EOL, num_samples/sample_freq); + pc.printf("Press enter to continue and then press again to quit" EOL); getchar(); for (int i = 0; i < num_samples; i++) { @@ -461,7 +461,7 @@ } else { pc.printf(" Sample:%d: Temperature:", i + 1); float temp = adt7420_get_temperature(device); - pc.printf("%.4f\n", temp); + pc.printf("%.4f" EOL, temp); wait_us(delay_sec); } } @@ -478,15 +478,15 @@ static uint8_t readback_reg() { - pc.printf(" Available registers:\n"); - pc.printf(" 1- Status\n"); - pc.printf(" 2- Configuration\n"); - pc.printf(" 3- Temperature\n"); - pc.printf(" 4- ID\n"); - pc.printf(" 5- Critical Temperature setpoint\n"); - pc.printf(" 6- Hysteresis Temperature setpoint\n"); - pc.printf(" 7- Temperature high setpoint\n"); - pc.printf(" 8- Temperature low setpoint\n"); + pc.printf(" Available registers:" EOL); + pc.printf(" 1- Status" EOL); + pc.printf(" 2- Configuration" EOL); + pc.printf(" 3- Temperature" EOL); + pc.printf(" 4- ID" EOL); + pc.printf(" 5- Critical Temperature setpoint" EOL); + pc.printf(" 6- Hysteresis Temperature setpoint" EOL); + pc.printf(" 7- Temperature high setpoint" EOL); + pc.printf(" 8- Temperature low setpoint" EOL); pc.printf(" Select a mode: "); uint16_t read_value = 0; @@ -495,7 +495,7 @@ if (input_check(new_mode, 1, 8, invalid_check) == FAILURE) { return FAILURE; } - pc.printf("%d\n", new_mode); + pc.printf("%d" EOL, new_mode); switch (new_mode) { case 1: @@ -525,7 +525,7 @@ default: break; } - pc.printf("Read value: 0x%x\n", read_value); + pc.printf("Read value: 0x%x" EOL, read_value); return SUCCESS; } @@ -539,7 +539,7 @@ *******************************************************************************/ static uint8_t reset_interface() { - pc.printf(" Resetting interface...\n"); + pc.printf(" Resetting interface..." EOL); adt7420_reset_interface(device); wait_us(RESET_DELAY); return SUCCESS; @@ -555,11 +555,11 @@ *******************************************************************************/ static uint8_t write_to_setpoint_reg() { - pc.printf(" Available registers:\n"); - pc.printf(" 1- Critical setpoint\n"); - pc.printf(" 2- Hystersis setpoint\n"); - pc.printf(" 3- Temperature high setpoint\n"); - pc.printf(" 4- Temperature low setpoint\n"); + pc.printf(" Available registers:" EOL); + pc.printf(" 1- Critical setpoint" EOL); + pc.printf(" 2- Hystersis setpoint" EOL); + pc.printf(" 3- Temperature high setpoint" EOL); + pc.printf(" 4- Temperature low setpoint" EOL); pc.printf(" Select a mode: "); int new_mode, invalid_check = 0; @@ -567,7 +567,7 @@ if (input_check(new_mode, 1, 4, invalid_check) == FAILURE) { return FAILURE; } - pc.printf("%d\n", new_mode); + pc.printf("%d" EOL, new_mode); float temp_c; @@ -591,36 +591,36 @@ if(new_mode == 2) write_value = round(temp_c); - else + else write_value = round(128 * temp_c); switch (new_mode) { case 1: if (adt7420_wr_setpoint_reg(device, REG_T_CRIT, write_value) == SUCCESS) - pc.printf("\n0x%x successfuly written\n", write_value); + pc.printf(EOL "0x%x successfuly written" EOL, write_value); else - pc.printf("\n0x%x NOT successfuly written\n", write_value); + pc.printf(EOL "0x%x NOT successfuly written" EOL, write_value); break; case 2: if (adt7420_wr_setpoint_reg(device, REG_HIST, write_value) == SUCCESS) - pc.printf("\n0x%x successfuly written (bits 7:4 are fixed at 0)\n", write_value); + pc.printf(EOL "0x%x successfuly written (bits 7:4 are fixed at 0)" EOL, write_value); else - pc.printf("\n0x%x NOT successfuly written\n", write_value); + pc.printf(EOL "0x%x NOT successfuly written" EOL, write_value); break; case 3: if (adt7420_wr_setpoint_reg(device, REG_T_HIGH, write_value) == SUCCESS) - pc.printf("\n0x%x successfuly written\n", write_value); + pc.printf(EOL "0x%x successfuly written" EOL, write_value); else - pc.printf("\n0x%x NOT successfuly written\n", write_value); + pc.printf(EOL "0x%x NOT successfuly written" EOL, write_value); break; case 4: if (adt7420_wr_setpoint_reg(device, REG_T_LOW, write_value) == SUCCESS) - pc.printf("\n0x%x successfuly written\n", write_value); + pc.printf(EOL "0x%x successfuly written" EOL, write_value); else - pc.printf("\n0x%x NOT successfuly written\n", write_value); + pc.printf(EOL "0x%x NOT successfuly written" EOL, write_value); break; default: - pc.printf("Invalid selection - try again.\n"); + pc.printf("Invalid selection - try again." EOL); wait(2); break; } @@ -637,11 +637,11 @@ *******************************************************************************/ static uint8_t set_fault_queue() { - pc.printf(" Available fault queue options:\n"); - pc.printf(" 1- 1 fault (default) \n"); - pc.printf(" 2- 2 faults\n"); - pc.printf(" 3- 3 faults\n"); - pc.printf(" 4- 4 faults\n"); + pc.printf(" Available fault queue options:" EOL); + pc.printf(" 1- 1 fault (default) " EOL); + pc.printf(" 2- 2 faults" EOL); + pc.printf(" 3- 3 faults" EOL); + pc.printf(" 4- 4 faults" EOL); pc.printf(" Select a mode: "); int new_fault, invalid_check = 0; @@ -649,7 +649,7 @@ if (input_check(new_fault, 1, 4, invalid_check) == FAILURE) { return FAILURE; } else { - pc.printf("%d\n", new_fault); + pc.printf("%d" EOL, new_fault); switch (new_fault) { @@ -666,7 +666,7 @@ adt7420_set_fault_queue(device, ADT7420_FAULT_QUEUE_4_FAULTS); break; default: - pc.printf("Invalid option\n"); + pc.printf("Invalid option" EOL); break; } return SUCCESS; } @@ -684,34 +684,34 @@ int new_polarity = 0; int new_mode, invalid_check = 0; - pc.printf(" Choose INT/CT mode:\n"); - pc.printf(" 1- Interrupt (default) \n"); - pc.printf(" 2- Comparator \n"); + pc.printf(" Choose INT/CT mode:" EOL); + pc.printf(" 1- Interrupt (default) " EOL); + pc.printf(" 2- Comparator " EOL); pc.printf(" Select a mode: "); invalid_check = pc.scanf("%d", &new_mode); if (input_check(new_mode, 1, 2, invalid_check) == FAILURE) { return FAILURE; } else { - pc.printf("%d\n", new_mode); + pc.printf("%d" EOL, new_mode); new_mode = (new_mode == 1) ? 0 : 1; adt7420_set_ct_int_mode(device, new_mode); } - pc.printf("\n Set output polarity for Critical and Over/Under Temperature pin:\n"); - pc.printf(" (Feature available only for internal sensors).\n"); + pc.printf(EOL " Set output polarity for Critical and Over/Under Temperature pin:" EOL); + pc.printf(" (Feature available only for internal sensors)." EOL); if(init_params.mbed_i2c_init.slave_address == INTERNAL_I2C || init_params.mbed_spi_init.chip_select == INTERNAL_SPI) { - pc.printf(" 1- Active Low (default) \n"); - pc.printf(" 2- Active High\n"); + pc.printf(" 1- Active Low (default) " EOL); + pc.printf(" 2- Active High" EOL); pc.printf(" Select a mode: "); invalid_check = pc.scanf("%d", &new_polarity); if (input_check(new_polarity, 1, 2, invalid_check) == FAILURE) { return FAILURE; } else { - pc.printf("%d\n", new_polarity); + pc.printf("%d" EOL, new_polarity); new_polarity = (new_polarity == 1) ? 0 : 1; adt7420_set_ct_int_polarity(device, new_polarity); } @@ -740,16 +740,16 @@ *******************************************************************************/ static void print_active_device(int external_internal_selection) { - const char* devices[7] = { "\n\n Active Device: ADT7410 I2C" , - "\n\n Active Device: ADT7420 I2C", - "\n\n Active Device: ADT7422 I2C", - "\n\n Active Device: ADT7310 SPI", - "\n\n Active Device: ADT7311 SPI", - "\n\n Active Device: ADT7312 SPI", - "\n\n Active Device: ADT7320 SPI"}; + const char* devices[7] = {EOL EOL " Active Device: ADT7410 I2C" , + EOL EOL " Active Device: ADT7420 I2C", + EOL EOL " Active Device: ADT7422 I2C", + EOL EOL " Active Device: ADT7310 SPI", + EOL EOL " Active Device: ADT7311 SPI", + EOL EOL " Active Device: ADT7312 SPI", + EOL EOL " Active Device: ADT7320 SPI"}; - const char* external_internal_print[] = {" - Internal Chip \n", - " - External Chip \n" }; + const char* external_internal_print[] = {" - Internal Chip " EOL, + " - External Chip " EOL }; pc.printf("%s %s", devices[init_params.act_device], external_internal_print[external_internal_selection - 1]); } @@ -770,9 +770,9 @@ int invalid_check) { if(invalid_check == 0 || input_val < lowest_accepted_val || input_val > highest_accepted_val) { - pc.printf("\n\n***** Invalid entry: No changes made *****\n"); + pc.printf(EOL EOL "***** Invalid entry: No changes made *****" EOL ); wait(WAIT_MENU_TIME); return FAILURE; } return SUCCESS; -} +} \ No newline at end of file