1

You initialize the serial communication via USB with

Serial.begin(baudrate);

where baudrate is a long specifying the number of symbols you want to send over the connection per second. You can put pretty much any number in there, but not every number makes sense.

One thing that I found odd though is that I can't seem to actually use a different baudrate than 9600. The sketch compiles and uploads just fine, but if I check the actual speed of the serial port via

setserial -ag port

where port is the port of my Teensy 4.0 board (that command is something you can use in the terminal of Linux) or with

Serial.baud();

directly in the sketch it always says 9600. I suspect that this is caused by something inside the code behind Serial.begin() since I can manually set the baudrate via the terminal in Linux using

stty speed baudrate < port > port

where (again) baudrate is the speed I want to use and port is the port of my board (checking it with the first terminal command: it works). But when restarting the program on the board the baudrate reverts to 9600.

Does anyone know why this is and how to fix this?

0

2 Answers 2

3

The whole concept of Baud Rate with USB communication is completely meaningless. There is no such thing as "baud rate" over USB.

What there is, and what you are confusing with "baud rate" is a configuration item which the host can send to the device which is a "I would like you to communicate with other devices at this speed" configuration item.

This is intended for use with USB to UART adaptors where it is used to configure the baud rate of a physical UART interface for downstream communication.

When you set the baud rate in your code it is ignored, since it has no meaning.

When you set the baud rate on your computer it sends it as this configuration value, which you can then retrieve, should you have an interest in that value, using the Serial.baud() function.

14
  • Of course there is a baudrate over USB. There is one for every communication. Do you mean to say that the Arduino IDE cannot change it?
    – LukasFun
    Commented Nov 21, 2019 at 16:38
  • @LukasFun No, there is no baud rate. There is a data rate, but that is largely unrelated to the actual rate of communication between the host and any one device, since it is a packet-based protocol.
    – Majenko
    Commented Nov 21, 2019 at 16:39
  • So... how do you control the data rate of the USB connection then, I guess? And why would that rate not matter?
    – LukasFun
    Commented Nov 21, 2019 at 16:41
  • You don't control the data rate. The data rate is defined by the class of the interface and device. USB 1 ("Full Speed") is 12Mbps. USB 2 ("High Speed") is 480Mbps. USB 3 ("Super Speed") is 5Gbps. The chosen speed is the highest that both the device (Arduino) and host (computer) can work together at.
    – Majenko
    Commented Nov 21, 2019 at 16:43
  • 1
    Sorry for coming back at this again. While the communication rate of the USB port per se may be fixed, this does not mean that the serial port is actually doing what I want (communicate with maximum speed). That's because the serial port used for this communication is only emulated via the USB port. And the connection of that emulated port should be customizable. It is, in fact, as I specified in my question but is reset every time the controller runs a sketch. Is there any way to change the speed of the connection? I actually tested the speed and it was about 60000 Bits/s. Quite slow.
    – LukasFun
    Commented Nov 28, 2019 at 16:07
0

The problem may be in flow control, as LukasFun suggested. Obviously, a low speed RS232 device will not be able to handle a continuous data stream at 1.5 Mbps

A quick look at this paper may help. https://www.usconverters.com/index.php?main_page=page&id=49&chapter=0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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