2019-09-06 01:33 PM
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.
Solved! Go to Solution.
2019-09-06 02:15 PM
Well for 16x
USART->BRR = usart_clock / baud_rate; // ie 4,000,000 / 9600
2019-09-06 02:15 PM
Well for 16x
USART->BRR = usart_clock / baud_rate; // ie 4,000,000 / 9600
2019-09-06 02:24 PM
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;
}
2019-09-06 02:32 PM
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.
-- pa
2019-09-06 03:09 PM
Thank you, will check it out.