Hello,
Thank you for your interest in my problem !
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.
- "16u2 USB/Serial converter" : This is Programming USB Port?
- "fractional BRG" : What does it mean in other words ?
westfw:
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.
westfw:
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
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
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!