I recently purchased an Arduino Due and have been trying for a few days now to get the Serial-USB connection to work. I was able to properly install the Arduino drivers and I have no problem programming the board over the Serial-USB connection. However, as soon as I attempt to use the Serial functionality in a programm, the USB connection ceases to work. While my program is running, I can still see the Arduino as a COM device, but no Serial data shows up through the Serial Monitor or through the Windows 7 PowerShell. If someone could give me guidance as to what might be wrong, I would be very greatful. Here is a list of symptoms and what I have tried so far:
System Specs: Windows 7 Home Professional, x64, running as a non-administrator account.
Using Arduino 1.5.7 Beta IDE.
I am using the USB cable that came with my Nexus 7.
Programming the Due over USB works fine on both the native USB port and the programming port
Pin 1 (TX) is outputting a signal when I call Serial.Write(), as I have tested by connecting pin 1 to pin 2 and setting pin 2 to a RISING interrupt.
Windows PowerShell shows that there are no bytes to read on the Due's Virtual COM Port (COM4)
Data transmission from computer to Due also does not seem to work, as Serial.available never rises above zero.
I have attempted updating the FDTI drivers from the FDTI website but this does not fix the problem.
I have tried running the IDE as administrator.
I have tried using both the native and programming ports for Serial communication, even though my understanding is that only the native port supports it.
The code I am using to test the connection:
volatile int itrCount = 1;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial);
pinMode(13,OUTPUT);
attachInterrupt(2,interrupt,RISING);
wait_for_contact();
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
char datIn = Serial.read();
Serial.print("I got: ");
Serial.write(datIn);
}
}
void wait_for_contact() {
while (Serial.available() <= 0)
{
Serial.println('A'); //Send char 65'
digitalWrite(13,HIGH);
delayMicroseconds(500000/itrCount);
digitalWrite(13,LOW);
delayMicroseconds(500000/itrCount);
}
}
void interrupt()
{
itrCount++;
}
Update: I tried the Due on another computer using the same USB cable and the problem persisted. I was able to program, but serial did not work. I am wondering whether the FDTI chip is broken.
I too am having a similar issue and seem to have tracked it down to the attachInterrupt call.
In short, I am trying to use and external interrupt to trigger SerialUSB.write. If I remove the attachInterrupt call I can connect and communicate via the native usb port no problems.
Any ideas?
#include <DueTimer.h>
int const numPnts = 1024;
int16_t read_times[2][numPnts];
int16_t values[2][numPnts];
volatile unsigned int i;
volatile int curBuf;
volatile int oldBuf;
volatile unsigned long startTime;
volatile unsigned long curTime;
const int extTrigPin = 31;
bool printValues = false;
//-----------------------------------------------------
void setup()
{
//Serial.begin(115200);
SerialUSB.begin(115200);
pinMode(A0, INPUT);
pinMode(extTrigPin,INPUT);
//if I comment the following two lines and add the attachInterrupt the SerialUSB call does not work.
Timer0.attachInterrupt(reset_values);
Timer0.start(24576);//
Timer1.attachInterrupt(daq_loop);
Timer1.start(24); // Calls every 24us
curBuf = 0;
//attachInterrupt(extTrigPin,reset_values,RISING);
}
//-----------------------------------------------------
void reset_values(){
//SerialUSB.println("triggered");
i = 0;//reset to zero
oldBuf = curBuf;//switch bufferID
curBuf = 1 - curBuf;//transform curBuf between 0 and 1
startTime = micros();//first start time for measurement (NOTE REPLACED IN daq_loop())
printValues ^= 1;//change print flag to send out values
// DEBUGGIN
// int j;
// for(j=0;j<100;j++) {
// Serial.print(j);
// Serial.print(" ");
// Serial.println(values[oldBuf][j]);
// }
// Serial.print(oldBuf);
// Serial.print(" ");
// Serial.print(curBuf);
// Serial.print(" ");
// Serial.println("DONE!");
}
//-----------------------------------------------------
void daq_loop(){
curTime = micros();
values[curBuf][i] = analogRead(A0);
read_times[curBuf][i] = curTime-startTime;
startTime = curTime;
//DEBUGGIN
// Serial.print(i);
// Serial.print(" ");
// Serial.print(values[curBuf][i]);
// Serial.print(" ");
// Serial.println(curBuf);
i+=1;
}
//-----------------------------------------------------
void loop()
{
if (printValues){ // print out the results
SerialUSB.write((uint8_t *)values[oldBuf],2048);
SerialUSB.write((uint8_t *)read_times[oldBuf],2048);//is this the best way or should we pack into 2D array?
printValues ^= 1;
}
}
This topic is a bit old but I got this problem too and found a solution.
The workaround I found is to change the priority of attachInterrupt in WInterrupts.c
Go to : C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino
Or if you can't find this folder it should be there :
C:\Users\user\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\cores\arduino
Open WInterrupts.c and change the priority on line 41, 47, 53 and 59 like this :
NVIC_SetPriority(PIOA_IRQn, 1); //was 0