Internal_Datalogger but with USB support removed (for MAX40108 Demo board), proof of concept that MAX32625 can be used successfully with VDDB(USB) left unpowered, as long as the USB library is not used.
Dependencies: max32625pico CmdLine
Diff: DataLogger_Internal.cpp
- Revision:
- 9:45f98573eb6d
- Parent:
- 8:dffee7509bfb
- Child:
- 10:04022a61b527
diff -r dffee7509bfb -r 45f98573eb6d DataLogger_Internal.cpp --- a/DataLogger_Internal.cpp Mon Nov 30 07:07:36 2020 +0000 +++ b/DataLogger_Internal.cpp Fri Dec 18 09:29:35 2020 +0000 @@ -88,7 +88,7 @@ //-------------------------------------------------- // Option to use SPI connected ADC #ifndef SPI_ADC_DeviceName -//~ #define SPI_ADC_DeviceName MAX11410 +#define SPI_ADC_DeviceName MAX11410 #undef SPI_ADC_DeviceName #endif #if defined(SPI_ADC_DeviceName) // SPI connected ADC @@ -1589,6 +1589,7 @@ //-------------------------------------------------- // print column header banner for csv data columns uint8_t Datalogger_Need_PrintHeader = true; +uint8_t need_reinit = true; void Datalogger_PrintHeader(CmdLine& cmdLine); void Datalogger_AcquireRow(); void Datalogger_PrintRow(CmdLine& cmdLine); @@ -1791,6 +1792,20 @@ 1.2, 1.2 }; +// Platform ADC individual channels 1=LSB, 2=Volt, 0=Disabled +typedef enum Platform_AIN_Enable_t { + Platform_AIN_Disable = 0, + Platform_AIN_Enable_LSB = 1, + Platform_AIN_Enable_Volt = 2, +} Platform_AIN_Enable_t; +uint8_t Platform_Enable_ch[NUM_DUT_ANALOG_IN_CHANNELS] = { + Platform_AIN_Enable_Volt, // AIN0 2=Volt + Platform_AIN_Enable_Volt, // AIN1 2=Volt + Platform_AIN_Enable_Volt, // AIN2 2=Volt + Platform_AIN_Enable_Volt, // AIN3 2=Volt + Platform_AIN_Enable_Volt, // AIN4 2=Volt + Platform_AIN_Enable_Volt, // AIN5 2=Volt +}; //-------------------------------------------------- // Option to log platform analog inputs as raw LSB code #ifndef LOG_PLATFORM_ANALOG_IN_LSB @@ -2006,20 +2021,89 @@ #if USE_SELFTEST cmdLine.serial().printf("\r\n . -- SelfTest"); #endif // USE_SELFTEST +#if USE_STAR_REG_READWRITE // * command read/write reg *reg? *reg=value +// CODE GENERATOR: help menu if has_register_write_command: *regname? -- read register; *regname=regvalue -- write register + cmdLine.serial().printf("\r\n * -- read core registers\r\n *regname? -- read register\r\n *regname=regvalue -- write register"); + // cmdLine.serial().printf("\r\n 01 23 45 67 89 ab cd ef -- write and read raw hex codes"); +#endif // USE_STAR_REG_READWRITE #if USE_DATALOGGER_TRIGGER // support Datalog trigger // TODO Datalog trigger menu // set Datalogger_Trigger to trigger_Halt or trigger_FreeRun // Datalogger_Trigger = trigger_Halt // halt the datalogger; continue accepting commands + // cmdLine.serial().print(F("\r\n L -- halt the datalogger; continue accepting commands")); + // // Datalogger_Trigger = trigger_FreeRun // free run as fast as possible cmdLine.serial().printf("\r\n LR -- Datalog free run as fast as possible"); + // + // TODO: Datalogger_Trigger = trigger_Timer // timer (configure interval) + // TODO: cmdLine.serial().printf("\r\n L_ -- Datalog _______"); // trigger_Timer + // + // TODO: Datalogger_Trigger = trigger_PlatformDigitalInput // platform digital input (configure digital input pin reference) + // TODO: cmdLine.serial().printf("\r\n L_ -- Datalog _______"); // trigger_PlatformDigitalInput + // + // TODO: Datalogger_Trigger = trigger_SPIDeviceRegRead // SPI device register read (configure regaddr, mask value, match value) + // TODO: cmdLine.serial().printf("\r\n L_ -- Datalog _______"); // trigger_SPIDeviceRegRead + // +#if defined(SPI_ADC_DeviceName) // SPI connected ADC + // LS<channel ID><verb>: Configure SPI_AIN channels + // channel ID: 0,1,2,... or - for all channels + // verb: D for disable, V for Voltage, L for LSB + cmdLine.serial().printf("\r\n LS-D -- Datalog SPI ADC channel '-'(all) Disable"); + cmdLine.serial().printf("\r\n LS-V -- Datalog SPI ADC channel '-'(all) Volt"); + cmdLine.serial().printf("\r\n LS-L -- Datalog SPI ADC channel '-'(all) LSB"); + cmdLine.serial().printf("\r\n LS2D -- Datalog SPI ADC channel channel 2 Disable"); + cmdLine.serial().printf("\r\n LS3V -- Datalog SPI ADC channel channel 3 Volt"); + cmdLine.serial().printf("\r\n LS4L -- Datalog SPI ADC channel channel 4 LSB"); + // + // MAX11410 verb for configuring SPI_AIN_Cfg_v_filter_ch[channel_index] + // cmdLine.serial().print(F("\r\n LS-CF34 -- Datalog SPI ADC channel channel 5 v_filter 0x34")); + cmdLine.serial().printf("\r\n LS-CF34 -- Datalog SPI ADC channel '-'(all) v_filter 0x34"); + // + // MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index] + // cmdLine.serial().print(F("\r\n LS-CC42 -- Datalog SPI ADC channel '-'(all) v_ctrl 0x42")); + cmdLine.serial().printf("\r\n LS-CC42 -- Datalog SPI ADC channel '-'(all) v_ctrl 0x42"); + // + // MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index] + // cmdLine.serial().print(F("\r\n LS5___ -- Datalog SPI ADC channel channel 5 v_ctrl")); + // MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index] + cmdLine.serial().printf("\r\n LS5CU -- Datalog SPI ADC channel channel 5 v_ctrl Unipolar"); + // ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) ? "BIPOLAR" : "Unipolar" + cmdLine.serial().printf("\r\n LS5CB -- Datalog SPI ADC channel channel 5 v_ctrl Bipolar"); + // ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) ? "BIPOLAR" : "Unipolar" + // + // MAX11410 verb for configuring SPI_AIN_Cfg_v_pga_ch[channel_index] + // cmdLine.serial().print(F("\r\n LS5CP00 -- Datalog SPI ADC channel channel 5 v_pga 0x00")); + cmdLine.serial().printf("\r\n LS-CP00 -- Datalog SPI ADC channel '-'(all) v_pga 0x00"); + // +#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC + // +#if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs + // LA<channel ID><verb>: Configure Platform_AIN channels + // channel ID: 0,1,2,... or - for all channels + // verb: D for disable, V for Voltage, L for LSB + cmdLine.serial().printf("\r\n LA-D -- Datalog Platform-AIN all-channel Disable"); +#if LOG_PLATFORM_ANALOG_IN_VOLTS + cmdLine.serial().printf("\r\n LA-V -- Datalog Platform-AIN all-channel Volt"); +#endif // LOG_PLATFORM_ANALOG_IN_VOLTS +#if LOG_PLATFORM_ANALOG_IN_LSB + cmdLine.serial().printf("\r\n LA-L -- Datalog Platform-AIN all-channel LSB"); +#endif // LOG_PLATFORM_ANALOG_IN_LSB + cmdLine.serial().printf("\r\n LA2D -- Datalog Platform-AIN channel 2 Disable"); +#if LOG_PLATFORM_ANALOG_IN_VOLTS + cmdLine.serial().printf("\r\n LA3V -- Datalog Platform-AIN channel 3 Volt"); +#endif // LOG_PLATFORM_ANALOG_IN_VOLTS +#if LOG_PLATFORM_ANALOG_IN_LSB + cmdLine.serial().printf("\r\n LA4L -- Datalog Platform-AIN channel 4 LSB"); +#endif // LOG_PLATFORM_ANALOG_IN_LSB +#endif // defined(LOG_PLATFORM_AIN) #endif // USE_DATALOGGER_TRIGGER support Datalog trigger # if HAS_AUX_SERIAL - cmdLine.serial().printf("\r\n LA -- Datalogger_enable_AUXserial %s", (Datalogger_enable_AUXserial?"disable":"enable")); + cmdLine.serial().printf("\r\n L>A -- Datalogger_enable_AUXserial %s", (Datalogger_enable_AUXserial?"disable":"enable")); # endif // HAS_AUX_SERIAL # if HAS_DAPLINK_SERIAL - cmdLine.serial().printf("\r\n LD -- Datalogger_enable_DAPLINKserial %s", (Datalogger_enable_DAPLINKserial?"disable":"enable")); + cmdLine.serial().printf("\r\n L>D -- Datalogger_enable_DAPLINKserial %s", (Datalogger_enable_DAPLINKserial?"disable":"enable")); # endif // HAS_DAPLINK_SERIAL - cmdLine.serial().printf("\r\n LS -- Datalogger_enable_serial %s", (Datalogger_enable_serial?"disable":"enable")); + cmdLine.serial().printf("\r\n L>S -- Datalogger_enable_serial %s", (Datalogger_enable_serial?"disable":"enable")); // //cmdLine.serial().print(F("\r\n ! -- Initial Configuration")); // @@ -2148,14 +2232,15 @@ //-------------------------------------------------- void main_menu_onEOLcommandParser(CmdLine& cmdLine) { - // TODO: process command line - cmdLine.serial().printf("\r\nCmdLine buf:"); - cmdLine.serial().printf("%s\r\n", cmdLine.str()); + // process command line + cmdLine.serial().printf("\r\nCmdLine buf:\"%s\"\r\n", cmdLine.str()); #if USE_DATALOGGER_TRIGGER // support Datalog trigger // If datalog is free running, halt on any possible received command if (Datalogger_Trigger == trigger_FreeRun) { Datalogger_Trigger = trigger_Halt; + cmdLine.serial().printf("Datalog stopped by USB command input\r\n"); + cmdLine.serial().printf("Restart datalog by sending LR\r\n"); } #endif // USE_DATALOGGER_TRIGGER support Datalog trigger @@ -2205,12 +2290,14 @@ } break; // case '%' #endif // APPLICATION_ArduinoPinsMonitor +#if USE_STAR_REG_READWRITE // * command read/write reg *reg? *reg=value +#endif // USE_STAR_REG_READWRITE // * command read/write reg *reg? *reg=value #if USE_DATALOGGER_TRIGGER // support Datalog trigger // TODO Datalog trigger menu // set Datalogger_Trigger to trigger_Halt or trigger_FreeRun // Datalogger_Trigger = trigger_Halt // halt the datalogger; continue accepting commands // Datalogger_Trigger = trigger_FreeRun // free run as fast as possible - case 'L': + case 'L': case 'l': { // halt the datalogger; continue accepting commands Datalogger_Trigger = trigger_Halt; @@ -2221,22 +2308,166 @@ Datalogger_Trigger = trigger_FreeRun; Datalogger_Need_PrintHeader = true; return; // instead of break; avoid falling through to print_command_prompt(); -# if HAS_AUX_SERIAL +#if defined(SPI_ADC_DeviceName) // SPI connected ADC + // LS<channel ID><verb>: Configure SPI_AIN channels + // channel ID: 0,1,2,... or - for all channels + // verb: D for disable, V for Voltage, L for LSB + case 'S': case 's': + { + for (int channel_index = 0; channel_index < NUM_DUT_ANALOG_IN_CHANNELS; channel_index++) { + if ((cmdLine[2] == '-' /* all channels */) + || (cmdLine[2] == '0'+channel_index) + ) + { + // it's me + // test cmdLine[3] to determine action + // Platform_Enable_ch[channel_index] = Platform_AIN_xxxxx; + switch (cmdLine[3]) + { + case 'D': case 'd': + SPI_AIN_Enable_ch[channel_index] = SPI_AIN_Disable; + break; + case 'L': case 'l': + SPI_AIN_Enable_ch[channel_index] = SPI_AIN_Enable_LSB; + break; + case 'V': case 'v': + SPI_AIN_Enable_ch[channel_index] = SPI_AIN_Enable_Volt; + break; + // + // + // TODO: MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index] + case 'C': case 'c': + { + uint8_t hexValue = 0; + hexValue = hexValueOfChar(cmdLine[5]) * 0x10 + hexValueOfChar(cmdLine[6]); + switch (cmdLine[4]) + { + // + // MAX11410 verb for configuring SPI_AIN_Cfg_v_filter_ch[channel_index] + // cmdLine.serial().print(F("\r\n LS-CF34 -- Datalog SPI ADC channel '-'(all) v_filter 0x34")); + case 'F': case 'f': + SPI_AIN_Cfg_v_filter_ch[channel_index] = hexValue; + break; + // + // MAX11410 verb for configuring SPI_AIN_Cfg_v_ctrl_ch[channel_index] + // cmdLine.serial().print(F("\r\n LS-CC42 -- Datalog SPI ADC channel '-'(all) v_ctrl 0x42")); + case 'C': case 'c': + SPI_AIN_Cfg_v_ctrl_ch[channel_index] = hexValue; + break; + // + // MAX11410 verb for configuring SPI_AIN_Cfg_v_pga_ch[channel_index] + // cmdLine.serial().print(F("\r\n LS-CP00 -- Datalog SPI ADC channel '-'(all) v_pga 0x00")); + case 'P': case 'p': + SPI_AIN_Cfg_v_pga_ch[channel_index] = hexValue; + break; + // + // cmdLine.serial().print(F("\r\n LS5CU -- Datalog SPI ADC channel channel 5 v_ctrl Unipolar")); + // ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) ? "BIPOLAR" : "Unipolar" + case 'U': case 'u': + SPI_AIN_Cfg_v_ctrl_ch[channel_index] = SPI_AIN_Cfg_v_ctrl_ch[channel_index] | 0x40; + break; + // + // cmdLine.serial().print(F("\r\n LS5CB -- Datalog SPI ADC channel channel 5 v_ctrl Bipolar")); + // ((SPI_AIN_Cfg_v_ctrl_ch[channel_index] & 0x40) == 0) ? "BIPOLAR" : "Unipolar" + case 'B': case 'b': + SPI_AIN_Cfg_v_ctrl_ch[channel_index] = SPI_AIN_Cfg_v_ctrl_ch[channel_index] &~ 0x40; + break; + } + break; + } + // + // + } + } // end if cmdLine[2] channel_index + } // end for channel_index + Datalogger_PrintHeader(); + Datalogger_Need_PrintHeader = true; + } + break; +#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC +#if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs + // LA<channel ID><verb>: Configure Platform_AIN channels + // channel ID: 0,1,2,... or - for all channels + // verb: D for disable, V for Voltage, L for LSB case 'A': case 'a': - Datalogger_enable_AUXserial = !Datalogger_enable_AUXserial; - Datalogger_Need_PrintHeader = true; + { + // all-channel: loop through all valid channel_index, test cmdLine[2] 'is it me'? + // for channel_index loop through 0..NUM_DUT_ANALOG_IN_CHANNELS + // if ((cmdLine[2] == '-' /* all channels */) + // || (cmdLine[2] == '0'+channel_index) + // ) { + // // it's me + // // test cmdLine[3] to determine action + // // Platform_Enable_ch[channel_index] = Platform_AIN_xxxxx; + // } end if cmdLine[2] channel_index + // } end for channel_index + for (int channel_index = 0; channel_index < NUM_PLATFORM_ANALOG_IN_CHANNELS; channel_index++) { + if ((cmdLine[2] == '-' /* all channels */) + || (cmdLine[2] == '0'+channel_index) + ) + { + // it's me + // test cmdLine[3] to determine action + // Platform_Enable_ch[channel_index] = Platform_AIN_xxxxx; + switch (cmdLine[3]) + { + case 'D': case 'd': + Platform_Enable_ch[channel_index] = Platform_AIN_Disable; + break; +#if LOG_PLATFORM_ANALOG_IN_LSB + case 'L': case 'l': + Platform_Enable_ch[channel_index] = Platform_AIN_Enable_LSB; + break; +#endif // LOG_PLATFORM_ANALOG_IN_LSB +#if LOG_PLATFORM_ANALOG_IN_VOLTS + case 'V': case 'v': + Platform_Enable_ch[channel_index] = Platform_AIN_Enable_Volt; + break; +#endif // LOG_PLATFORM_ANALOG_IN_VOLTS + } + } // end if cmdLine[2] channel_index + } // end for channel_index + if (Datalogger_enable_serial) { + Datalogger_PrintHeader(cmdLine); + } + # if HAS_AUX_SERIAL + if (Datalogger_enable_AUXserial) { + Datalogger_PrintHeader(cmdLine_AUXserial); + } + # endif // HAS_AUX_SERIAL + # if HAS_DAPLINK_SERIAL + if (Datalogger_enable_DAPLINKserial) { + Datalogger_PrintHeader(cmdLine_DAPLINKserial); + } + # endif // HAS_DAPLINK_SERIAL + Datalogger_Need_PrintHeader = true; + } break; +#endif // defined(LOG_PLATFORM_AIN) + case '>': + // L>A -- Datalogger_enable_AUXserial + // L>D -- Datalogger_enable_DAPLINKserial + // L>S -- Datalogger_enable_serial + switch (cmdLine[2]) + { +# if HAS_AUX_SERIAL + case 'A': case 'a': + Datalogger_enable_AUXserial = !Datalogger_enable_AUXserial; + Datalogger_Need_PrintHeader = true; + break; # endif // HAS_AUX_SERIAL # if HAS_DAPLINK_SERIAL - case 'D': case 'd': - Datalogger_enable_DAPLINKserial = !Datalogger_enable_DAPLINKserial; - Datalogger_Need_PrintHeader = true; - break; + case 'D': case 'd': + Datalogger_enable_DAPLINKserial = !Datalogger_enable_DAPLINKserial; + Datalogger_Need_PrintHeader = true; + break; # endif // HAS_DAPLINK_SERIAL - case 'S': case 's': - Datalogger_enable_serial = !Datalogger_enable_serial; - Datalogger_Need_PrintHeader = true; - break; + case 'S': case 's': + Datalogger_enable_serial = !Datalogger_enable_serial; + Datalogger_Need_PrintHeader = true; + break; + } + break; // case '>' L>S serial enable toggle } } break; // case 'L' @@ -2341,20 +2572,25 @@ #endif // VERIFY_PART_ID_IN_LOOP #endif // defined(SPI_ADC_DeviceName) // SPI connected ADC #if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs - for (int channel_index = 0; channel_index < NUM_PLATFORM_ANALOG_IN_CHANNELS; field_index++, channel_index++) { + for (int channel_index = 0; channel_index < NUM_PLATFORM_ANALOG_IN_CHANNELS; channel_index++) { + if (Platform_Enable_ch[channel_index] == Platform_AIN_Disable) { + continue; + } // comma between fields if (field_index > 0) { cmdLine.serial().printf(","); } + field_index++; // AIN_index column header prefix cmdLine.serial().printf("\"A%d", channel_index); -#if LOG_PLATFORM_ANALOG_IN_LSB - // _LSB column header suffix - cmdLine.serial().printf("_LSB\""); -#elif LOG_PLATFORM_ANALOG_IN_VOLTS - // _V column header suffix - cmdLine.serial().printf("_V\""); -#endif + if (Platform_Enable_ch[channel_index] == Platform_AIN_Enable_LSB) { + // _LSB column header suffix + cmdLine.serial().printf("_LSB\""); + } + if (Platform_Enable_ch[channel_index] == Platform_AIN_Enable_Volt) { + // _V column header suffix + cmdLine.serial().printf("_V\""); + } } #endif // defined(LOG_PLATFORM_AIN) // end of column header line @@ -2431,6 +2667,7 @@ // PART_ID field: Device ID Validation if (part_id_readback != part_id_expect) { cmdLine.serial().printf(",\"FAIL\""); + need_reinit = true; #if defined(SPI_ADC_DeviceName) // SPI connected ADC g_MAX11410_device.Init(); g_MAX11410_device.v_filter = SPI_AIN_Cfg_v_filter_ch[0]; @@ -2444,22 +2681,57 @@ #endif // VERIFY_PART_ID_IN_LOOP #endif // defined(SPI_ADC_DeviceName) // SPI connected ADC #if defined(LOG_PLATFORM_AIN) // Datalog Arduino platform analog inputs - for (int channel_index = 0; channel_index < NUM_PLATFORM_ANALOG_IN_CHANNELS; field_index++, channel_index++) { - // if (Platform_Enable_ch[channel_index] == Disable) { - // continue; - // } + for (int channel_index = 0; channel_index < NUM_PLATFORM_ANALOG_IN_CHANNELS; channel_index++) { + if (Platform_Enable_ch[channel_index] == Platform_AIN_Disable) { + continue; + } // comma between fields if (field_index > 0) { cmdLine.serial().printf(","); } + field_index++; + if (Platform_Enable_ch[channel_index] == Platform_AIN_Enable_LSB) { #if LOG_PLATFORM_ANALOG_IN_LSB - cmdLine.serial().printf("%u", Platform_LSB[channel_index]); -#elif LOG_PLATFORM_ANALOG_IN_VOLTS - cmdLine.serial().printf("%6.6fV", Platform_Voltage[channel_index]); -#endif // #if LOG_PLATFORM_ANALOG_IN_LSB LOG_PLATFORM_ANALOG_IN_VOLTS + cmdLine.serial().printf("%u", Platform_LSB[channel_index]); +#endif + } + if (Platform_Enable_ch[channel_index] == Platform_AIN_Enable_Volt) { +#if LOG_PLATFORM_ANALOG_IN_VOLTS + cmdLine.serial().printf("%6.6fV", Platform_Voltage[channel_index]); +#endif + } } #endif // defined(LOG_PLATFORM_AIN) + if (need_reinit) { +#if defined(SPI_ADC_DeviceName) // SPI connected ADC + if (g_MAX11410_device.Init() == 0) { + //~ cmdLine.serial().printf(",\"Init() failed\""); + } else { + //~ cmdLine.serial().printf(",\"Init() success\""); +#if USE_CUSTOM_REG_INIT // custom_reg_init_addr[], custom_reg_init_data[], custom_reg_init_count + // in Datalogger_PrintRow(), when part_id test fails, + // apply list of custom register writes after re-init + // custom_reg_init_addr[], custom_reg_init_data[], custom_reg_init_count + for (unsigned int index = 0; index < custom_reg_init_count; index++) { + uint8_t regAddress = custom_reg_init_addr[index]; + uint32_t regData = custom_reg_init_data[index]; + cmdLine.serial().printf("*%s=0x%06.6x", g_MAX11410_device.RegName(regAddress), regData); + g_MAX11410_device.RegWrite((MAX11410::MAX11410_CMD_enum_t)regAddress, regData); + } +#endif // USE_CUSTOM_REG_INIT + g_MAX11410_device.v_filter = SPI_AIN_Cfg_v_filter_ch[0]; + g_MAX11410_device.v_ctrl = SPI_AIN_Cfg_v_ctrl_ch[0]; + g_MAX11410_device.v_pga = SPI_AIN_Cfg_v_pga_ch[0]; + need_reinit = false; + } +#else // defined(SPI_ADC_DeviceName) // SPI connected ADC + need_reinit = false; +#endif // defined(SPI_ADC_DeviceName) // SPI connected ADC + } cmdLine.serial().printf("\r\n"); + if (need_reinit) { + //~ delay(500); // platform_delay_ms 500ms timing delay function + } } // void Datalogger_PrintRow() // example code main function