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:
#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.