2019-12-25 11:53 PM
please tell me whether it is eval board hardware problem or not, but i cam able to achieve 312500 baud rate for UART1.
thanks.
2019-12-27 02:08 AM
Is it USART1 or USART2 then? Note that all possible pin mappings for USART2 are connected to onboard peripherals on the eval board, it might be possible to use it after removing some bridges or jumpers first. Check the board user manual if you have meant USART2.
USARTs can have different clock sources. Check out RCC_CFGR3 in the reference manual. You might want to switch the clock source to SYSCLK for better accuracy, you can do it by
RCC->CGFR3 |= RCC_CFGR3_USART1SW_0;
for USART1, or
RCC->CGFR3 |= RCC_CFGR3_USART2SW_0;
for USART2. Other clock sources are possible, but they'd make sense mostly for lower baud rates.
Now check the system clock frequency. Verify that it's really what you think it is (and what the application requires). You can output it to the MCO pin and check with an oscilloscope. (Enable GPIOA clock in the RCC, set PA8 to alternate mode, function 0, set RCC_CFGR_MCO_2)
Calculate the baudrate divisor, divide the system clock frequency with the required baudrate, and round it to the nearest integer. Note the error introduced by rounding, at 8MHz system clock it can be as high as 1.5%. A proper UART should tolerate frequency deviations up to 5%, so this is indeed no problem in itself.
Enable the required USART and GPIO peripherals in RCC. Set the pins to alternate mode, and set the function number (from the datasheet).
Write the divisor calculated above into the USART1->BRR register, then issuing
USART1->CR1 |= USART_CR1_UE|USART_CR1_TE|USART_CR1_RE;
should get the USART going. If it still doesn't, double-check the register values and frequencies.
2020-01-14 01:45 AM