Go Down

Topic: Speed Serial USB Programming Port 0,00% Error (Read 1 time) previous topic - next topic

Tfou57

Jul 31, 2020, 07:30 pm Last Edit: Jul 31, 2020, 07:46 pm by Tfou57
Hello
I need to use a Serial 8N+1 with the baud rate with 0.00% error

The code only receives permanent data frames from PC software.
My problem is that when the PC program starts or when it stops it sends a single frame.

Code: [Select]
void setup ()
{
   Serial.begin (250000);
   while (! Serial);
}


I observe that there are single frames emitted during starts and stops which are rejected for nonconformity.

1) I want to know with which Baud rate, Serial has no transmission error
2) Do I have to configure Serial otherwise?

Thank you for your help !

Tfou57

Hello,
Doesn't anyone have any feedback on this?

What are the serial transmission speeds that you find most reliable on the Due

Thank you for your information!...

westfw

250000bps should have 0% error on the 16u2 USB/Serial converter, and the Due cpu itself has a fractional BRG, so you shouldn't be getting errors due to mismatched bitrates.  There is probably some other problem, but you haven't provided enough information to even guess what it might be.

Usually opening the serial port will cause an Arduino to go through a hardware reset.  Perhaps it is not done resetting by the time your PC-side starts sending data.

Tfou57

#3
Aug 09, 2020, 01:12 pm Last Edit: Aug 10, 2020, 03:14 pm by Tfou57
Hello,
Thank you for your interest in my problem !

250000bps should have 0% error on the 16u2 USB/Serial converter, and the Due cpu itself has a fractional BRG, so you shouldn't be getting errors due to mismatched bitrates. 
-  "16u2 USB/Serial converter" : This is Programming USB Port?
-  "fractional BRG" : What does it mean in other words ?


Usually opening the serial port will cause an Arduino to go through a hardware reset.  Perhaps it is not done resetting by the time your PC-side starts sending data.
A reading error when receiving motor position commands in a 5-byte frame updated every 2 ms is not a problem.

The SimTools PC software is the "Master" and the Arduino Due acts as a "Slave".

The problem is that especially when the SimTools PC software controls the start and stop of Arduino code execution

The two 5 byte frames that should not be missed are the XS00C frame sent only once at start up" and the XE00C frame sent only once when the SimTools "Master" PC software is stopped.


There is probably some other problem, but you haven't provided enough information to even guess what it might be.
Here is a summary of the 6 different combinations of the Serial function used in the code:

In void setup() Serial.begin(250000);   and while (!Serial);

When the PC software sends 5-byte frames every 2 ms to the USB programming port

In void SerialWorker() while(Serial.available()) and Serial.read() : ( Posted below )

In void loop() if(Serial.available()) : With or without this test (Serial.available() , delayMicroseconds(25) in void SerialWorker() is required
This test In void loop() is implemented because the Arduino Due calculates positions according to the serial frames on the serial port (motor position setpoints) and ADC readings (motor feedback positions).


When the software on the PC does not send anything to the USB Programming Port (SimTools PC software stopped)
In void ParseCommand () Serial.print and Serial.println single per switch...case for display of the configuration on the serial monitor by manual consultation when the software on the PC does not send anything to the USB Programming Port (SimTools PC software stopped)
In void FeedbackPotWorker() Serial.print and Serial.println single per switch...case for display of the configuration on the serial monitor by manual consultation when the software on the PC does not send anything to the USB Programming Port (SimTools PC software stopped)

In void setup(), I declare
Code: [Select]
Serial.begin(250000);                     // Ouvre le port série Programming Port et fixe son débit à 115200 bauds.
  while (!Serial);                         // Attend que la connexion soit établie sur le Programming Port



Frame read function with delayMicroseconds (25) at the end

Code: [Select]
void SerialWorker()
{
  int buffer = 0;
  int buffercount = -1;                           // En attente de la reception d'un octet -> Etat initial de la variable buffercount=-1

  while(Serial.available())                       // Boucle sans fin, et indéfinie tant que des données entrantes sont présentes sur le port série                                                                 // Etait while(Serial.available())
  {                                     
    if(buffercount==-1)                           // Aucun 1er octet conforme
    {
      buffer = Serial.read();                     // Lecture de l'octet sur le port série
      if(buffer != 'X')
      {
        buffercount=-1;                           // Rejet de l'octet reçu si le premier octet n'est pas un X
      }
      else
      {
      buffercount=0;                              //  commandbuffer[0] = Octet conforme <=> X est conservé
                //emplacement delay fct mal car long à réagir
      }
    }
    else                                          // Après la réception de l'octet <=> X , les 3 octets suivant seront lus
    {
      buffer = Serial.read();
      commandbuffer[buffercount]=buffer;           // commandbuffer[1] commandbuffer[2] commandbuffer[3]  commandbuffer[4]
      buffercount++;
      if(buffercount > 3)                         // Une trame de 5 octets a été lue, commandbuffer[0] à  commandbuffer[4]
      {
        if(commandbuffer[3]=='C')                 // Si le 4ème octet lu est un C, la trame complète reçue est validée conforme et utilisable ParseCommand()
        {
               //Trying to locate the DelayMicroseconds that does not allow the Loop ( ) to work
          ParseCommand();                         // Interprétation de la trame reçue une fois cette trame validée complète et conforme,
               //Trying to locate the DelayMicroseconds that does not allow the Loop ( ) to work
        }
              //eTrying to locate the DelayMicroseconds that does not allow the Loop ( ) to work
        buffercount=-1;                           // Remise à l'état initial de la variable buffercount=-1
              //Trying to locate the DelayMicroseconds that does not allow the Loop ( ) to work
      }
      delayMicroseconds(25);     //delayMicroseconds(25) delayMicroseconds(25) does not allow the Loop ( ) loop to work if Programming USB Port 250000 bauds .
                 // The SimTools software to the Arduino DUe the frame of 5 bytes every 2ms at 250000
  }                     
}



Thank you for your help!

westfw

Quote
-  "16u2 USB/Serial converter" : This is Programming USB Port?
Yes.  You might get better results on the Native USB port.  Both in the sense that the set bitrate is irrelevant, and that the "open" negotiations on the PC side might be more synchronized with the Arduino coming up.

Quote
-  "fractional BRG" : What does it mean in other words ?
It means that the SAM3X ought to be "reasonably accurate" for any bit rate within reason.  This doesn't mean that there aren't bugs that prevent some speed from being accurate, but that should be unlikely.


Quote
The problem is that especially when the SimTools PC software controls the start and stop of Arduino code execution
I do not understand what "start and stop of Arduino code" means.  Hardware reset?  Some in-band signal on the serial port?  Something else?

I know nothing about "simTools."

Tfou57

Hello

I do not understand what "start and stop of Arduino code" means.  Hardware reset?  Some in-band signal on the serial port?  Something else?

I know nothing about "simTools."

Here are some details

SimTools is a software for extracting telemetry from certain games in order to drive a dynamic simulator.
https://www.xsimulator.net/community/marketplace/motion-simulation-software-simtools.63/
Once SimTools is configured for a game, when a game starts, SimTools detects its launch.
To simplify:
1) It sends an XS00C frame on the serial link declaring that it has detected the launch of the game and starts the extraction of telemetry data.
2) After this single XS00C frame, it sends on the serial port at a configured period (2ms for example) the position commands to be applied to each simulator engine.
3) The Arduino detects 5 bytes frames starting with an X and ending with a C. The Arduino is able to send the position commands to each engine of the simulator.
4) The arduino reads the current position of each motor ( ADC reading ).
5) Depending on the current position and the setpoint position to be reached, the Arduino calculates and controls the motor positioning correction to be applied ....
....
6) When the game stops, SimTools detects its stop and sends an XE00C frame so that the Arduino stops the simulator on a preconfigured stop position.

Go Up