2016-08-18 01:28 AM
Hello, I disovered some weird behaviour with STM32F10x standard peripheral lib V.3.5.0: When I try to set a UART baud rate of 215,000 B/s via USART_Init() function, it results in a baud rate of 250,000 B/s instead (BRR = 0x60 at 24MHz). When I choose 214,000 or 216,000 everything works fine.
Is that a known bug?
#stm32-stdperiph_lib2016-08-18 02:27 PM
C:\MSVC\STM32>usartf1
96 60 250000
112 70 214285
111 6F 216216
#include <windows.h>
#include <stdio.h> typedef unsigned long uint32_t;
typedef unsigned char uint8_t; void baud(uint32_t apbclock, uint32_t baudrate)
{
uint32_t tmpreg = 0x00;
uint32_t integerdivider = 0x00;
uint32_t fractionaldivider = 0x00;
int over8 = 0; /* Determine the integer part */
if (over8)
{
/* Integer part computing in case Oversampling mode is 8 Samples */
integerdivider = ((25 * apbclock) / (2 * baudrate));
}
else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
{
/* Integer part computing in case Oversampling mode is 16 Samples */
integerdivider = ((25 * apbclock) / (4 * baudrate));
}
tmpreg = (integerdivider / 100) << 4; /* Determine the fractional part */
fractionaldivider = integerdivider - (100 * (tmpreg >> 4)); /* Implement the fractional part in the register */
if (over8)
{
tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t)0x07);
}
else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
{
tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F);
} /* Write to USART BRR */
// USARTx->BRR = (uint16_t)tmpreg; printf('%3d %02X %10d
', tmpreg, tmpreg, apbclock / tmpreg); }
int main(int argc, char **argv)
{
baud(24000000, 215000);
baud(24000000, 214000);
baud(24000000, 216000); return(1);
}
2016-11-08 07:57 PM