Baudrate setting vs. formula (incorrect?)

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

Hi,

 

with SAME53J18 I have used Atmel Start to configure SERCOM in USART-mode and to have 38400 Baud.
My input clock is 4MHz.
In debug mode I read the baud register value to be 0xFE6D. In CTRLA reg, SAMPR is 0 -> 16x arithmetic baud rate generation.
I have checked with a scope that my output baudrate is correct (bit time is 26µs).
When I look at the formula in data sheet page 829 it is stated: F_baud= (F_ref/16) * (1 - Baud/65536).
So with this Baud register setting and above formula, F_baud= 1537 (???).
When I use given other formula to calculate baud rate register value, I get 55470 = 0xD8AE. Which is also not the setting.
Does anybody know the correct formula? What did I get wrong?
Please help. Thank you.

 

Meanwhile I did some Tests:
Baud reg value                    Bit duration          Baud rate

0x8000                               323ns                  3 095 975

0xF000                               2.565µs                  389 863

0xFF00                               40.95µs                    24 420

0xFFFF                               10.8ms                            92.59

Can someone figure out the formula to it?
 

PS:
I have found out now, that when I enable ctrlb.COLDEN= 1, then the USART TXD does not function any more!
Just to warn others to use it...

 

This topic has a solution.

Surprise: As soon as one's doing it correctly - it works!

Last Edited: Mon. Jul 11, 2022 - 06:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Something like this 
 

#ifndef CONF_SERCOM_0_USART_BAUD_RATE
#define CONF_SERCOM_0_USART_BAUD_RATE                                                                                  \
	65536 - ((65536 * 16.0f * CONF_SERCOM_0_USART_BAUD) / CONF_GCLK_SERCOM0_CORE_FREQUENCY)
#endif

will be the source of the value in the register. If we plug in your intended values we indeed get 55470 (or 55469 if truncated). So some value is not what you expect, check hpl_sercom_config.h for the actual values used.
/Lars

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

Thank you Lajon,
I will check that tomorrow - soon there is finishing time!
...But the value Atmel Start has set correctly is 65133 decimal!
 

>> ...check hpl_sercom_config.h
Unfortunately it seems that this file is not part of my project...
I will search for it. 

Surprise: As soon as one's doing it correctly - it works!

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

DrDatasalad wrote:
...But the value Atmel Start has set correctly is 65133 decimal!

Probably because the SERCOM core frequency is not 4MHz.
/Lars

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

[want] 38400 Baud.  My input clock is 4MHz.

Why 4MHz?  While it looks like the numbers should work OK, I would consider 38400 @ 4MHz to be "uncomfortably close" to the edges of possible bitrates (where small changes in the BRG settings result in large changes of actual bitrate.)  Maybe the BRG in the SAMD chips is immune to that sort of problem.  Maybe not.

(also, I find the "arithmetic" BRG to be "weird", and prefer the "fractional" BRG, which is more obvious.)

 

 

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

westfw wrote:

Why 4MHz? 

Because it is my external reference clock.

Now I see that the calculating formula in Atmel Start driver is really as lars stated, is calculated with the core clock frequency (100MHz)!

So then, what is the "slow clock" in Atmel Start setting for?
I thought, that the core clock is for the bus interface of the peripheral and the slow clock is for baudrate generation...

Surprise: As soon as one's doing it correctly - it works!

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

I think the SERCOM slow clock is used for SMBus timeouts only. It is in the datasheet, search for "slow clock".

/Lars

 

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

Hi Lars,

thank you very much for all your qualified advice!

Surprise: As soon as one's doing it correctly - it works!