Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Software serial can't receive messages when debugging? (Read 220 times)
fantasyhpu
Newbies
*
Offline



Posts: 2
Software serial can't receive messages when debugging?
Jan 17th, 2020 at 3:16am
 
Hi, I want to debug arduino uno, I followed the instructions posted in arduino project hub:
https://create.arduino.cc/projecthub/visualmicro/arduino-uno-debugging-f4d470?f=...
and my test code is:
Code (C++):
#define _DEBUG 1

#ifdef _DEBUG
#include <SoftwareSerial.h>
#include <avr8-stub.h>
#include <app_api.h>
#define USE_SERIAL SWSerial
SoftwareSerial USE_SERIAL(2, 3);
#else
#define USE_SERIAL Serial
#endif


const int NUMBER_OF_FIELDS = 3;
int fieldIndex = 0;
int values[NUMBER_OF_FIELDS] = { 0 };

void setup()
{
#ifdef _DEBUG
    debug_init();
#endif
    USE_SERIAL.begin(9600);
}

void loop()
{
    USE_SERIAL.println(fieldIndex);
    if (USE_SERIAL.available())
    {
        char ch = USE_SERIAL.read();
        if (ch >= '0' && ch <= '9')
        {
            if (fieldIndex < NUMBER_OF_FIELDS)
            {
                values[fieldIndex] = (values[fieldIndex] * 10) + (ch - '0');
            }
        }
        else if (ch == ',')
        {
            fieldIndex++;
        }
        else
        {
            for (int i = 0; i < min(NUMBER_OF_FIELDS, fieldIndex); i++)
            {
                USE_SERIAL.println(values[i]);
                values[i] = 0;
            }
            fieldIndex = 0;
        }
    }
}
 


The serial port used to upload the sketch is COM9, and the serial port generated by the USB-to-Serial board is COM7.
When debugging, I can get the messages output by "USE_SERIAL.println(fieldIndex);", but the COM7 can't receive the messages I send to it (the message is "12,1,3"), as the test.git file illustrated, so the "debug arrow" can't enter the "if (USE_SERIAL.available()) {...}" statement.

For a test, I quit the debug session, and upload the code to arduino uno, then I open serial monitor and select COM7 and click the "Connect" button in the "Serial | COM7" window, typing "12,1,3", then click the "send data to the connected device", I find that the software serial works very well.

But why the software serial port can not receive messages in the debug session?
Can anyone tell me how to do with it?
Best regards.
Back to top
« Last Edit: Jan 17th, 2020 at 7:54am by fantasyhpu »  

test.gif (870 KB | )
test.gif
 
IP Logged
 
Simon Hopkinson
Administrator
*****
Offline



Posts: 186
Re: Software serial can't receive messages when debugging?
Reply #1 - Jan 17th, 2020 at 10:41am
 
This may be a limitation of the GDBStub Implementation (receiving data), as when it is paused on a break point, there are no interrupts happening either.

The Serial Debugger may be a better option for the Uno in this case, and it allows changing data on the fly when sat on a break point as you require.

To move to this select "Debug: Serial", and remove the GDBStub changes and library from your code.

The Serial debugger requires re-upload of the code when breakpoints are edited or added, so add in the points to stop or trace now.  Variables can be added for editing using the Breakpoint Actions and {variableName} syntax.

An example video showing this feature (used for calibration often) is on Youtube Here.

Further Info:
Serial Debugger
Serial Debug Breakpoint Actions

Back to top
« Last Edit: Jan 17th, 2020 at 11:39am by Simon Hopkinson »  
 
IP Logged
 
fantasyhpu
Newbies
*
Offline



Posts: 2
Re: Software serial can't receive messages when debugging?
Reply #2 - Jan 17th, 2020 at 11:48am
 
Simon Hopkinson wrote on Jan 17th, 2020 at 10:41am:
This may be a limitation of the GDBStub Implementation (receiving data), as when it is paused on a break point, there are no interrupts happening either.

The Serial Debugger may be a better option for the Uno in this case, and it allows changing data on the fly when sat on a break point as you require.

To move to this select "Debug: Serial", and remove the GDBStub changes and library from your code.

The Serial debugger requires re-upload of the code when breakpoints are edited or added, so add in the points to stop or trace now.  Variables can be added for editing using the Breakpoint Actions and {variableName} syntax.

An example video showing this feature (used for calibration often) is on Youtube Here.

Further Info:
Serial Debugger
Serial Debug Breakpoint Actions



Hi, thank you very much for tellimg me the reasons.
Best regards.
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print