I am trying to figure out how to configure the USART of the mentioned discovery board for a transmission of 14400,8,N,1. My problem is that I don't know what to put in the USARTx\$\rightarrow\$BRR register. I know it has something to do with the following formula (according to the manual): $$Tx/Rx\;Baud=\frac{f_{CK}}{8\times(2-OVER8)\times USARTDIV}$$ And the BRR register has the following format: enter image description here What I know is that for a communication of 9600,8,N,1 the value used is USART1\$\rightarrow\$BRR=0x00000D05 (is this supposed to be 9600?). I have understand the 8,N,1 part that are configured in the CR1 and CR2 registers.

I know that \$f_{CK}=32MHz\$ (I don't know if it can be changed somehow). The \$USARTDIV\$ value seems to be the one to be written in the BBR register, like in this example:

enter image description here

\$OVER8\$ is configured in CR1. Some tables like these appear in the manual that are supposed to help to compute the baudrate: enter image description here enter image description here The clock tree used is the following: enter image description here

  • \$\begingroup\$ Whe have no idea how you're settting up the clock tree or what crystal you use. \$\endgroup\$ – Turbo J Apr 11 '18 at 10:30
  • \$\begingroup\$ @TurboJ I'll upload it \$\endgroup\$ – Martín Apr 11 '18 at 10:41
  • \$\begingroup\$ Download the standard peripherals library STSW-STM32077 to see how the initialization is done. The library includes ready demos for the discovery board. \$\endgroup\$ – filo Apr 11 '18 at 10:58

fCKis the APB clock frequency, I just can't find where the manual actually says that. As long as both APB1 and APB2 are the same, 32MHz, you don't have to worry which one. If they were different, then you would have to keep in mind that USART1 is on APB2, the others are on APB1. APB frequencies can be changed using RCC->CR and RCC->CFGR, but these changes are global, affecting all peripherals on that bus.

At the default 16 bit oversampling, BRR is simply the ABP frequency divided by the desired baudrate.

When OVER8=0, BRR is a fixed point number with 4 bits (0-3) holding the fractional part, i.e. 1/16 units, and the integer part is shifted left 4 bits. This is just a complicated way of saying that BRR=USARTDIV*16. Consider the original formula, with OVER8=0 it becomes Baud=fCK/(8*2*USARTDIV), therefore USARTDIV*16=BRR=fCK/Baud.

Let's verify it, 32000000/9600=3333, which is 0xD05 in hex, good. Now, for 14400 baud you'd need 32000000/14400=2222 in BRR.

It gets more complicated when using 8 bit oversampling (OVER8=1), with a "hole" in BRR at bit 3, but it would be needed only when using higher baud rates.


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.