6
\$\begingroup\$

As I understand it, in PC-to-MCU communications over USB CDC, specifying a baud rate is only necessary when the MCU sends its received data to a UART. The baud rate is needed by the bridging device to know the signalling rate to be used on the TX/RX lines.

For example, the ATMEGA16U2 used with the ATMEGA328 on Arduino Unos is responsible for receiving USB packets from the PC and translating them to UART signals for the ATMEGA328. So I can see why it is important that the ATMEGAU2 and ATMEGA328 agree on a baud rate.

I've read somewhere that the PC ignores any baud rate setting used with USB CDC. And yet, when a wrong baud rate is set in the PC serial terminal, gibberish is received, even though the data is received over USB without any traces of UART stench on it. The only case where I think baud rate should matter on a PC is when data is being transmitted by the PC to the bridge. I imagine baud rate information is sent along with the data so that the bridge can know at what speed to signal the receiving UART.

What is wrong with my assumptions? When and why is baud rate relevant at the PC's end in USB CDC communications?

\$\endgroup\$
3
  • \$\begingroup\$ (a guess) because the 16U2 and 328 are not 'agreeing on a baud rate'. The 16U2 is simply setting itself to whatever baud rate is selected by the PC. It's acting as a simple USB UART under the PC's control. \$\endgroup\$ – brhans Jul 20 '16 at 0:53
  • 1
    \$\begingroup\$ @brhans Your guess sounds very sensible, now that I think about it. I always assumed the process of receiving data (by the PC) is entirely passive, i.e. the 16U2 sends an interrupt of some kind when it has data available. But you seem to be suggesting that even the act of setting the PC terminal to some baud rate, is communicated to the 16U2 which proceeds to listen to the 328P at this rate. \$\endgroup\$ – SoreDakeNoKoto Jul 20 '16 at 0:58
  • 2
    \$\begingroup\$ Usb is not an interrupt based bus. It polls continuously. \$\endgroup\$ – Passerby Jul 20 '16 at 3:03
7
\$\begingroup\$

The ATmega16U2 used in the Arduino Uno is acting as a USB to serial converter, connected to the ATmega328P that you're programming. Setting the baud rate on the USB CDC serial device causes the ATmega16U2 to set its UART to that baud rate, so setting an incorrect baud rate prevents proper communications between the two chips.

If you were using an Arduino based on an ATmega32U4 -- such as the Arduino Leonardo or Arduino Micro -- the USB CDC baud rate would not matter, as the AVR interprets "serial" data directly from the USB stream. (Indeed, you can send data in either direction however fast you want; the baud rate has no effect on transfer rates.)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.