the following line was perfectly working in Arduino Uno.
...
byte LVcmd[11]; // 11 Bytes of command from host
...
for (int i=0; i<11; i++)
{
LVcmd = Serial.read(); // Build Command From Serial Buffer } ... Now, with the Arduino Due, it seems not working (checked the content of Lvcmd...). Have I to take care of something new ?
During these last tests it looks that the transmission of data to the Arduinoi Due resets the hardware.
I have in fact a confirmation character sent back only from void stup() to check the initialization and every many time I send a string of data to the USB port this character is sent (not always, only sometime).
I am thinking that for some unknown reasons the serial port is resetting the hardware.
Is there any interrupt or timer involved in Serial ?
My sketch uses the TC1 Ch 0 and TC3_IRQn
The port is recognized by the PC, in fact I am using it to program the Due.
The sketch is really complex (but working in Arduino Uno) and I am adapting it for the Due.
I am using the standard serial library that comes with the IDE 1.5.2
I will simplify the sketch to isolate the problem, but for the moment I am suspecting an hardware reset when the USB of the Due receives data from the PC.
Notice that the Serial.print("K"); is written only in the setup loop, but sporadically it arrives also in the interfaced PC.
The PC runs with a standard LabView application from the National Instruments examples and it works properly.
// This is the setup:
void setup(void) {
Serial.begin(9600); // Baud Rate 1 Mbps
while (!Serial) {};
delay(2000);
Serial.print("K");
Serial.flush();
pinMode(4,OUTPUT); // Pin 4 - DCC Signal
startTimer(TC1, 0, TC3_IRQn, 19200); // TC1 channel 0, IRQ and 58 us
}
The problem is not related only to the Serial.Read, but in the serial communication at whole.
Neither this simple program works, or, it works with the IDE monitor, but not with the interfaced PC.
In the interfaced PC runs a very simple program from the examples of LabView, test many and may times...it works with everything, but not with Arduiino Due.
Tried to set in many way the port, such as 9600, 1, n, 1 etc, but never found the way to communicate.
What I receive from Arduino Due is alway a "K" or a "W" and sometime some trash.
Notice that the "K" is sent only at the setup loop.
The Led in pin 13 goes ON automatically (never set ON in the sketch...) every time I send a byte
Definitively, every time I send a byte, the Arduino Due resets it self !
What a hell is happening ?
//******************************************************************************************
// Setup (executed only one time
//******************************************************************************************
void setup(void)
{
Serial.begin(9600); // Baud Rate test may values as 1200, 115200, 9600 etc..., no one works
while (!Serial);
pinMode(13,OUTPUT); // This pin is ON at power on (?) and it goes on every time I send a byte with the PC, I can reset it via pin input 10
pinMode(10,INPUT); // Just for test, used to resetpin output 13 (led) that is on by it self (?)
Serial.print("K"); // This print is in setup loop, then sent only one time, but it appears time by time when I send bytes from the PC
Serial.flush();
}
//******************************************************************************************
// Main Loop
//******************************************************************************************
void loop(void)
{
if(Serial.available() >0)
{
Serial.print("W");
}
if (digitalRead(10) == 0) {digitalWrite(13,0);}
delay(100);
}
My Due can upload the sketch, but has problems during the communication with the PC.
May be this is the problem, but I do not know how to find the R23 in the layout.
My Arduino Due is Rev3.
Where can I find the layout and schematic of the Due ?
found the drawings and located the R23.
jumped the R23, but still the problem remains.
I am definitively convinced: the Arduino Due resets it self when a byte arrives in the serial port.
Remark: downloading the sketch is not a problem, only the communications with the PC generates the reset.
May be there is one way to disable the master reset...?...
Hello giubio51,
Normally, when you wait for serial data is to read it, but if you only want to write 'W' each time a character is sent via serial, a good way to empty Serial.available() is using Serial.read()as follows:
//******************************************************************************************
// Setup (executed only one time
//******************************************************************************************
void setup(void)
{
Serial.begin(9600); // Baud Rate test may values as 1200, 115200, 9600 etc..., no one works
while (!Serial);
pinMode(13,OUTPUT); // This pin is ON at power on (?) and it goes on every time I send a byte with the PC, I can reset it via pin input 10
pinMode(10,INPUT); // Just for test, used to resetpin output 13 (led) that is on by it self (?)
Serial.print("K"); // This print is in setup loop, then sent only one time, but it appears time by time when I send bytes from the PC
Serial.flush();
}
//******************************************************************************************
// Main Loop
//******************************************************************************************
void loop(void)
{
if(Serial.available() >0)
{
Serial.read();
Serial.print("W");
delay(200);
}
if (digitalRead(10) == 0) {digitalWrite(13,0);}
delay(100);
}
...and I have to admit it was a my big mistake in the LabView side.
Instead of looping with the read and write operations, I was sending also a reset of the port (VISA port clear) at every loop in the LabView side.
This instruction was resetting also the Arduino Due.
By clearing the port at the first loop and then operating with serial read and write only, the problem disappeared.
Now the communications are working at full speed without problems.
Sorry for the wrong considerations regarding the Arduino Due.
This time the fault was mine.