arduino / arduino/ArduinoCore-avr

Possible bug in arduino-usbserial.c

Open
#188 4 comments 0 reactions 1 assignee Claimed by @cmaglie View on GitHub
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi, I posted this already to the Arduino Forum but it did not get any attention there.
I just found this GitHub page and think it is a much better place for reporting bugs.

My Arduino UNO Rev3 jumped into my UART Rx interrupt when connecting or changing the baudrate/parity settings with a terminal tool (in this case hTerm).
Analyzing the Rx connection of the atmega328p showed me that there are short down pulses on the Rx line. The uC interprets these short pulses as UART data when using a baudrate of 19200Bd and 38400Bd but not when using 9600Bd.
Digging through the schematics and the source code of the atmeg16u2 finally brought me to the function EVENT_CDC_Device_LineEncodingChanged() in Arduino-usbserial.c.
This function is obviously called every time the user connects to the virtual COM device and also when changing the UART settings within the terminal program. Before applying the new UART settings the UART is disabled with the following lines:
/\* Must turn off USART before reconfiguring it, otherwise incorrect operation may occur */
UCSR1B = 0;
UCSR1A = 0;
UCSR1C = 0;

As long as the UART is activated the Tx line of the mega16u2 (M8RXD in the schematic) idles high.
Disabling the UART reconfigures the Tx line as an input which results in a short down pulse until the UART is reinitialized.

I was able to fix this behavior by adding the following lines before the UART is disabled:

   /\* Prevent Tx1 Pin from going low for a short time when temporarily turning off the USART in the next lines*/
   DDRD &= ~(1<

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.