Skip to main content
KHuyn
Associate III
September 6, 2019
Solved

How to edit USART BAUDRATE using only register header file?

  • September 6, 2019
  • 4 replies
  • 1219 views

Hello everyone.

I am trying to edit the baudrate using register header file without using HAL. I am working with STM32L4R5ZI and IAR complier.

I found these lines in the header files but don't know how to use them.

/****************** Bit definition for USART_BRR register *******************/
#define USART_BRR_DIV_FRACTION_Pos (0U)
#define USART_BRR_DIV_FRACTION_Msk (0xFUL << USART_BRR_DIV_FRACTION_Pos) /*!< 0x0000000F */
#define USART_BRR_DIV_FRACTION USART_BRR_DIV_FRACTION_Msk /*!< Fraction of USARTDIV */
#define USART_BRR_DIV_MANTISSA_Pos (4U)
#define USART_BRR_DIV_MANTISSA_Msk (0xFFFUL << USART_BRR_DIV_MANTISSA_Pos) /*!< 0x0000FFF0 */
#define USART_BRR_DIV_MANTISSA USART_BRR_DIV_MANTISSA_Msk /*!< Mantissa of USARTDIV */

I am trying to config USART3 to transmit some char only. Oversampling rate = 8, usart _ker_ckpres = 4Mhz

Thank you guys in advance.

This topic has been closed for replies.
Best answer by Tesla DeLorean

Well for 16x

USART->BRR = usart_clock / baud_rate; // ie 4,000,000 / 9600

4 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
September 6, 2019

Well for 16x

USART->BRR = usart_clock / baud_rate; // ie 4,000,000 / 9600

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
KHuyn
KHuynAuthor
Associate III
September 6, 2019

Thanks you, your works perfectly

void initUSART3(void)
{
 USART3->BRR |= 0x1A0U;
 USART3->CR1 |= USART_CR1_TE;
}

Just also figured out how to use them with those code

void initUSART3(void)
{
 USART3->BRR |= USART_BRR_DIV_FRACTION;
 USART3->BRR |= (0x1AU << 4) & USART_BRR_DIV_MANTISSA;
 USART3->CR1 |= USART_CR1_TE;
}

Pavel A.
September 6, 2019

Even if you don't use the HAL libraries, it often is worth to check out "LL" library.

Many of it's functions are macros/inlines so you don't get any bloat.

https://github.com/STMicroelectronics/STM32CubeL4/blob/f6877af03b5c8b666b3443f5295cf95ec9c0b15d/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_ll_usart.h#L1972

-- pa

KHuyn
KHuynAuthor
Associate III
September 6, 2019

Thank you, will check it out.