2025-09-26 6:20 PM
Hello,
I am learning bare metal programming for STM32F446RE and am trying to write a simple transmit driver for USART2. I managed to do it but my only problem is when I use HSI 16Mhz clock speed (or anything lower) I get a weird first character. When I use a higher clock speed it works fine (using another clock source).
Does anyone know the reason for that?
Thank you
void USART_init(){
RCC->APB1ENR|=(1<<17);
USART2->CR1&=~(1<<12);
USART2->CR1&=~(1<<10);
USART2->CR1&=~(1<<15);
USART2->CR1|=(1<<13);
// Baud Rate of 115200 and Clock of 16Mhz
USART2->BRR=(8<<4 | 11);
USART2->CR1|=(1<<3);
USART2->CR1|=(1<<2);
char g[15];
sprintf(g,"Hello\r\n");
for(int i=0;i<strlen(g);i++){
while(!(USART2->SR & (1<<7)));
USART2->DR=g[i];
}
while(!(USART2->SR & (1<<6)));