Go Down

Topic: Communications problems solved (Read 330 times) previous topic - next topic

kilr0y

Jun 22, 2018, 05:03 pm Last Edit: Jul 05, 2018, 04:02 pm by kilr0y
I wrote the attached program "keyboard.c" which sends an unbuffered keystroke to my Arduino DUE at 28800 baud.
The DUE is programmed with the attached "stepper_test.ino", which is a modification of the code provided by Sparkfun Electronics for the Big Easy stepper motor driver. My understanding is that, if I transmit over the "programming USB port" at 9600 baud, it will reprogram the DUE. However, since I am communicating at 28800 baud, communication should go as programmed.

My understanding is that if there is nothing to send, the request for input from the DUE (dueout in line 72 of the keyboard program) should result in a zero.  Instead, I am getting bufr = 'k' (or some other random character).
??

PS Hopefully, someone else will find keyboard.c to be useful.

pjrc

Some Linux kernels have a bug in their CDC driver when the baud rate is configured for 14400 or 28800 (which is silly, since the baud rate isn't really used).

Recommend using 38400 or any of the other standard rates.

kilr0y

Thank you.
In the process of changing the IO speed for the computer, I discovered that the command to change the IO speed was incorrect. B38400 actually equals 15. FYI, see attached corrected keyboard.c

Now I am getting different garbage in reply from the DUE.
Am I setting the communications speed incorrectly in the DUE sketch?

Some Linux kernels have a bug in their CDC driver when the baud rate is configured for 14400 or 28800 (which is silly, since the baud rate isn't really used).

Recommend using 38400 or any of the other standard rates.

gdsports

I would use the same baud rate used by the IDE to upload code. If the upload speed is 115200, set Serial.begin(115200) and open the serial console window at 115200. The menu should appear. Close the serial console window then run the keyboard program also running at 115200.

As far as I know 9600 is not a special baud except is it a lot slower than 115200. 1200 is a special baud rate which results in erase and reset of the board to get it ready for the next upload.

The Due has two micro USB ports. One is labelled the Programming port and the other the Native USB port. Both appear as USB serial ports to a computer. The programming port is connected to an ATmega16U2 and UART0 port so baud rate matters on this port. Baud rate does not matter on the native USB port because there is no UART.

I also would not use oddball baud rates such as 28800. I do not see any reason to use different speeds for upload versus serial console.

kilr0y

Menu?? I don't have any communication with the DUE board except thru the USB cable to the computer. And apparently, I don't have that communication either.

My keyboard program reports the existing flag settings prior to any changes. Thus, I know what flag settings the Arduino IDE uses during upload. I tried using those flag settings, and simply changed the communication speed from that used by the IDE. No joy. Still garbage from the DUE UART. I tried changing the connection from the programming port to the other USB port. No output from the DUE at all.

I would use the same baud rate used by the IDE to upload code. If the upload speed is 115200, set Serial.begin(115200) and open the serial console window at 115200. The menu should appear. Close the serial console window then run the keyboard program also running at 115200.

As far as I know 9600 is not a special baud except is it a lot slower than 115200. 1200 is a special baud rate which results in erase and reset of the board to get it ready for the next upload.

The Due has two micro USB ports. One is labelled the Programming port and the other the Native USB port. Both appear as USB serial ports to a computer. The programming port is connected to an ATmega16U2 and UART0 port so baud rate matters on this port. Baud rate does not matter on the native USB port because there is no UART.

I also would not use oddball baud rates such as 28800. I do not see any reason to use different speeds for upload versus serial console.


gdsports

See if you can get this to work on the programming port. Upload it at whatever upload speed seems to work for you.

Code: [Select]
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("Hello world!");
  delay(1000);
}


Open the serial console monitor (Ctrl-Shift-M). See the speed to 9600. Do you see anything? Try different speeds but the speed in Serial.begin(9600) must match the serial monitor speed.

If this does not work, something is broken on your system.

kilr0y

SUCCESS!
The trick was:
Code: [Select]
ack = read(USB, bufr +i++, 1);
if((ack < 0) && (errno == 11)){ // errno = 11 means device unavailable
  sleep(1);
  continue;
}


Quote
See if you can get this to work on the programming port. Upload it at whatever upload speed seems to work for you.

Code: [Select]

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("Hello world!");
  delay(1000);
}




Open the serial console monitor (Ctrl-Shift-M). See the speed to 9600. Do you see anything? Try different speeds but the speed in Serial.begin(9600) must match the serial monitor speed.

If this does not work, something is broken on your system.

kilr0y

Attached find a working, non-canonical interface between DUE board and USB port on a computer that is POSIX compliant (Apple, BSD, Linux). In other words, pressing a '1' key on the keyboard is immediately sent to the Arduino board, without accompanying new line character.
Although the interface is non-canonical (does not halt transmission pending carriage return), buffering is provided after receipt.

Go Up