cancel
Showing results for 
Search instead for 
Did you mean: 

How to edit USART BAUDRATE using only register header file?

KHuyn
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

Well for 16x

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4

Well for 16x

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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.
Evangelist III

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

Thank you, will check it out.