Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Soft Serial debugging (Read 7904 times)
Marius
Developer
****
Offline


Posts: 204
Location: Centurion RSA
Joined: Sep 7th, 2011
Soft Serial debugging
Jul 5th, 2012 at 5:02pm
Print Post  
Please explain or see if I have this right.

I have a piece of code that enables the main serial on the uno for other communications. I also open the softserial on pin 6 and 7 for the debugger.
However, download is still via the main serial and when I send anything down there the debugger still answers. I dont get the breakpoints either.

Am I doing this right or was the intention with the softserial something else?
Code
Select All


#include <SoftwareSerial.h>
String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

SoftwareSerial Serial1(6,7);

//Serial1.begin(115200);

void setup() {
  // initialize serial:

  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

 

  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Soft Serial debugging
Reply #1 - Jul 5th, 2012 at 9:26pm
Print Post  
Please clear out the RemotePort property which contains Serial1 from your earlier testing.

With SoftwareSerial it's best to enter the pin numbers, the RemotePort property allows you to instantiate your own SoftwareSerial port which you are not doing in this case. 

The RemotePort property overrides the TX/RX pins so that's why it still tries to send over Serial1 in your test.

You also need to set the RemoteTransport to SoftwareSerial

By the way, in your first test, when using HardwareSerial, the default is Serial1 and 115200. So you didn't need to enter RemotePort, RemoteSpeed, Remote Transport, LocalPort or Local Speed. The debugger would have simply opened up on the upload port at 115200. To debug on the main upload port we only need one property "Enable Debug=Full"
« Last Edit: Jul 5th, 2012 at 9:30pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Soft Serial debugging
Reply #2 - Jul 5th, 2012 at 9:32pm
Print Post  
By the way, in my haste to keep the debug strings on the local pc and not on the arduino I forgot to bring user/code strings through to the variables reader. It's a minor change that should be in a version within the next week.
  
Back to top
WWW  
IP Logged
 
Marius
Developer
****
Offline


Posts: 204
Location: Centurion RSA
Joined: Sep 7th, 2011
Re: Soft Serial debugging
Reply #3 - Jul 6th, 2012 at 7:06am
Print Post  
Thanks man, I understand the workings of it all now. Embarrassed

There is still one funny in my test. There is a breakpoint in the loop() and I have an event from the serial port. It would seem that the breakpoint is reached but not halted the code. I can continually trigger the event and the debugger will update the variables every time. Is this because of the event in the code or am I doing it wrong again?
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Soft Serial debugging
Reply #4 - Jul 6th, 2012 at 9:14am
Print Post  
Not sure, I haven't tested the break/pause very much. I've done more trace stuff.

I suggest that the serialEvent be treated like a timer event which has little access to the core. read the stuff in serial but put a breakpoint in the loop or main code where you check your serial arrived flag (stringComplete)

FYI

When you press F5 to continue a breakpoint VS just sends 1 byte of data over the serial. The actual problem is more likely to be an arduino issue with reading softwareserial in the serialEvent. The F5 Continue on breakpoints will ONLY auto continue if arduino says that there is softserial data available. So the question is "why does arduino say there is bytes available from softerial in the serial event?? It seems wrong. I'll test it more and write this up when I get a mo.

PS:

You don't really need to use the serialEvent, it's more for novices. This would work the same way, interested to know if we still have a problem if we do it this way?

[code]
void loop() {  
RunMainProgram();
ReadSerial1();
}

void RunMainProgram()
{
// print the string when a newline arrives:  
if (stringComplete) {   
Serial.println(inputString);     
// clear the string:   
inputString = "";    
stringComplete = false;  
}
}

void ReadSerial1()
{
while (Serial.available()) 
{  
  // get the new byte:   
char inChar = (char)Serial.read();    
// add it to the inputString:   
inputString += inChar;    
// if the incoming character is a newline, set a flag   
// so the main loop can do something about it:    

if (inChar == '\n') 
{     
stringComplete = true;    
}  
}
}

[/code]
« Last Edit: Jul 6th, 2012 at 10:00am by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint