1
\$\begingroup\$

serial monitor

After typing C, microcontroller responds with #
Next, I type k, microcontroller responds with #INFO: TWI master enabled
Next, I type !, microcontroller responds with C

after typing in the next command "EG", the screen gives that error. i have tried screen package on linux and it has the same issue.

switch (command){
        case 'E': //Experiment options
            experiment_handler(getchar());
            break;

        case 'S': //Settings options
            settings_handler(getchar());
            break;

        case 'T': ;
            uint16_t tcs_data[] = {0,0,0,0};
            if (settings.settings.tcs_enabled == 0){
                printf("T-1.-1.-1.-1\n");
            }
            else {
                tcs_readvalues(tcs_data);
                printf("#INFO: TCS—%u %u %u %u\n", tcs_data[0], tcs_data[1], tcs_data[2], tcs_data[3]);
                printf("T%u.%u.%u.%u\n", tcs_data[0], tcs_data[1], tcs_data[2], tcs_data[3]);
            }
            break;

        case 'V': //check version
            #define STRING2(x) #x
            #define STRING(x) STRING2(x)
            #pragma message "GIT_COMMIT = " STRING(GIT_COMMIT)
            printf("V%u.%u.%u-%s\n", BOARD_VER_MAJOR, BOARD_VER_MINOR, BOARD_VER_MICRO, GIT_COMMIT);
            break;

        default:
            printf("#ERR: Command %c not recognized\n", command);
            return;
    }
    printf("no\n");
    return;
}

int main(void){

    board_init();
    pot_init();
    pmic_init();

    irq_initialize_vectors();
    cpu_irq_enable();
    sleepmgr_init();
    sysclk_init(); //Disables ALL peripheral clocks D:
    rtc_init();
    sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_EVSYS);

    pmic_set_scheduling(PMIC_SCH_ROUND_ROBIN);

    delay_ms(500);

    stdio_usb_init();
    stdio_usb_enable();

    ads1255_init_pins();
    ads1255_init_module();

    PORTD.INT0MASK = PIN5_bm;
    PORTD.INT1MASK = PIN5_bm;
    PORTD.INTCTRL = PORT_INT0LVL_OFF_gc | PORT_INT1LVL_OFF_gc;

    max5443_init_pins();
    max5443_init_module();

    ads1255_wakeup();
    ads1255_rdatac();
    ads1255_standby();

    ads1255_setup(ADS_BUFF_ON,ADS_DR_60,ADS_PGA_2);

    autogain_enable = 0;
    g_gain = POT_GAIN_30k;
    pot_set_gain();

    settings_read_eeprom();

    wdt_set_timeout_period(WDT_TIMEOUT_PERIOD_8KCLK); // 8 secs

    //  Wait for application connection - Get 'c', reply '#', get 'k'
    while(1){
        while(getchar() != 'c');
        putchar('#');
        while(getchar() != 'k');
        printf("\n\r");
        break;
    }

    tcs_init();
    wdt_enable();

    program_loop:
        while(getchar() != '!');
        printf ("C\n");
        command_handler(getchar());
        wdt_reset();
    goto program_loop;
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Please explain why this is a problem of electrical engineering. \$\endgroup\$ – Janka Jul 10 at 0:04
  • \$\begingroup\$ which text character causes the issue? ... do any other text characters cause the same failure? \$\endgroup\$ – jsotola Jul 10 at 0:10
  • \$\begingroup\$ text character 'EG' ps: 'G' is from another source code in the same firmware as the main.c program i uploaded above \$\endgroup\$ – Hero Jul 10 at 5:23
  • 1
    \$\begingroup\$ Can you describe the serial connection is more detail? Is via USB? Does it involve a dedicated USB-to-UART chip or is it done in software in the microcontroller? The serial protocol does not have any features to terminate a connection. So it's more likely that the underlying USB connection was terminated, either due to a power issue or due to a sofware crash if the USB to UART conversion is done in software. \$\endgroup\$ – Codo Jul 10 at 6:50
  • 2
    \$\begingroup\$ Most likely your experiment_handler function crashed or blocked the microcontroller. Therefore, the USB connection becomes unresponsive and the PC terminated the USB connection (incl. the serial connection). \$\endgroup\$ – Codo Jul 10 at 6:56
1
\$\begingroup\$

The MCU hangs (or resets due to not handling the watchdog on time), so it stops handling the USB protocol stack, and PC thinks the cable is detached so USB serial port stops existing. You have a problem in the MCU firmware.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.