Mega2560 board USB connection speed

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Back again,

  I am using the hardware, but not the IDE for this little project.  I would like to use the USB interface on the M2560 to talk to the PC terminal program, but I am not sure what speed the thing talks at natively.  I know that you can set up the baud rate in the Arduino IDE to pretty much anything, so am I correct in guessing that the on board 16a2 has an autobaud routine in it?

 

What happens if the M2560 uses a CH340 instead?

 

Thanks.

JImEDIT:

 

I plan on changing the crystal on the board for the M2560 from 16Mhz to 7.3728Mhz and wiping the fuse settings to allow a wider Baud rate range with minimal error if it means anything

This topic has a solution.

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Mon. Nov 18, 2019 - 11:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
I plan on changing the crystal on the board for the M2560 from 16Mhz to 7.3728Mhz and wiping the fuse settings to allow a wider Baud rate range with minimal error if it means anything

Why?

It works just fine with 16MHz crystal.

I use the bootloader whether it is C, C++, ASM, ... or Arduino.

 

You can use the USB-Serial chip whether 8u2, 16u2, CH340, ...

With programs in any language.    You just write to the USART in the normal way.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CH340 doesn't like anything above 115200 methinks.

 

Using 14.745MHz might be a better choice for the crystal - keep the cpu speed up. As David suggests, keep the 16MHz unless there is a compelling reason to change. If you expect to do multiple high speed usarts, then using a different chip might be a better choice. If you use the Arduino libraries, then it is a no-brainer to change hardware.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
It works just fine with 16MHz crystal

Kartman wrote:
As David suggests, keep the 16MHz unless there is a compelling reason to change.

 

Baud rates I will be using.  I want to be as close to 0.0% error as possible for all baud rates from 1200 to 115.2k as per the datasheet for USART1.

 

 

The question is, does it matter what baud rate I send out of USART0 to the USB interface?  It's merely for status information

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if you tell your PC program to connect via usb->serial at 9600 baud, that's what it will use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Got it.

 

Thanks Russell.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Standard" baud rates (9600, 15k2 etc) are not "native" for usb-serial converters. 16u2 at arduino mega256 works perfectly at 500kbps, ch340 - at 1mbps, ft232r and pl2303 at 2mbps. At list under Linux.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The 16u2 ( and CH340x) takes the UART information  {most often in 8 data bits, No Parity, 1 stop bit (8/N/1) format} and converts it into the complex USB hardware/software protocol. 

 

   UART is a tethered interconnection with a one-to-one communications cable between two stand-alone microprocessors.  USB is more of a miniature network between a host computer and a very wide range of possible peripherals.  USB is much more complex than UART.

 

As I understand it, the 16u2 (or CH340x) will determine the baud rate automatically.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

changing the baud rate changes the speed of the serial connection FROM the 16u2 (a control packet goes out over USB, and the 16u2 receives it and manipulates the UART appropriately), but it won't actually change the speed of data transfer over the USB connection (though that ends up flow-controlled at higher levels of the USB stack, so you might not be able to tell the difference.)

 

If you use an "Arduino-like device" with native USB support, the speed you put in the Serial.begin() on the sketch side, or the speed you set the com port to on the PC side, will be irrelevant, and data transfer will go much faster than you expect.  I get around 6Mbps between SAMD21 and Mac, for example.   https://www.pjrc.com/teensy/benc...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
changing the baud rate changes the speed of the serial connection FROM the 16u2 (a control packet goes out over USB, and the 16u2 receives it and manipulates the UART appropriately)

 

Ok, so the 16u2 or CH340 is using an Autobaud scheme to set itself then?

 

westfw wrote:
but it won't actually change the speed of data transfer over the USB connection (though that ends up flow-controlled at higher levels of the USB stack, so you might not be able to tell the difference.)

I figured that much as usb speeds are device/host port dependent

 

 

THe reason for my question was in fact the 'Serial.begin()'  My not knowing how the Arduino IDE works on the back end (nor have I explored this either) had me wondering if the IDE does something when the sketch is downloaded into the target, does the IDE set the baud rate on both the target processor and the USB interface's as well.  Since I am not using the Arduino IDE, >>I am only using the hardware, and first time using the hardware's USB for status<<, I wanted to see if there was anything I needed to do accordingly.

 

Not going to worry about it then.

 

Thnaks

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so the 16u2 or CH340 is using an Autobaud scheme to set itself then?

No autobaud.  Serial.begin() sets the UART speed of the ATmega, and the side will set the speed of the 16u2 or CH340 (even if you don't explicitly set it, it'll have a default speed sent in the handshake associated with the "open" calls.)  If those speeds don't match, you'll get the usual "serial speeds don't match" noise-like data.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, but as I have said, I am not using the arduino IDE, so what is the default speed, or how would I set the baud rate in Studio?

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
so what is the default speed
Surely the speed of the Vcom is set by your PC terminal software? That must filter all the way down to the FTDI/CH430/16U2 or whatever that is doing the USB-UART conversion.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Surely the speed of the Vcom is set by your PC terminal software?

I would think the same, but Westfw wrote:

 

westfw wrote:
changing the baud rate changes the speed of the serial connection FROM the 16u2 (a control packet goes out over USB, and the 16u2 receives it and manipulates the UART appropriately)

 

I would guess that when the USB/ttl interface >whatever that IC may be< enumerates, the PC sets a default rate.  If I go into the Device Manager and change the settings the Interface IC will be set accordingly.  No sense in guessing it now as I will have my Megas on Monday and can see what happens, then I will report back here what I get.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mega16U2 will set its baud.

USB UART - some are more baud precise than others and some have FBRG.

Windows 10 also sets baud.

 

https://github.com/arduino/ArduinoCore-avr/blob/master/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial.c#L209

FBRG - Fractional Baud Rate Generator

 

Which CP210x matters :

CP210x_Comparison (Silicon Labs)

 

crystal-less, up to 460800 bps :

MCP2221A - USB - USB Bridge

 

SerialDevice.BaudRate Property (Windows.Devices.SerialCommunication) - Windows UWP applications | Microsoft Docs

 

"Dare to be naïve." - Buckminster Fuller