Weird character from UART. STM32L100RC

I'm having problems communicating with UART on my STM32L100RC discovery board. I get character such as xþ when I'm sending the letter 'F'. I'm using Hercule to receive data. Hercule's configuration is : Baudrate = 9600, Data size = 8, Parity = None, Hankshake = OFF and Mode = Free. So here is my code and if you can tell me what I do wrong, I'd be very grateful!

Also, I think it is important that I specify that I can get my code working using the HAL library (but I can't use it for my program), so that puts my physical hardware out of the equation.

void UART_Initialization (void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

// Initializing RX_Pin
GPIO_InitTypeDef GPIO_InitStructRX;
GPIO_InitStructRX.GPIO_Pin = RX_Pin;
GPIO_InitStructRX.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructRX.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructRX.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructRX);

// Initializing TX_Pin
GPIO_InitTypeDef GPIO_InitStructTX;
GPIO_InitStructTX.GPIO_Pin = TX_Pin;
GPIO_InitStructTX.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructTX.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructTX.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructTX.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructTX);

USART_InitTypeDef USART_InitStructUSART;
USART_InitStructUSART.USART_BaudRate = 9600;
USART_InitStructUSART.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructUSART.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructUSART.USART_Parity = USART_Parity_No;
USART_InitStructUSART.USART_StopBits = USART_StopBits_1;
USART_InitStructUSART.USART_WordLength = USART_WordLength_8b;
USART_Init(USART1, &USART_InitStructUSART);

// Setting alternate functions for RX_Pin and TX_Pin
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);

USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
USART_Cmd(USART1, ENABLE);

}

void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_DATA(Data));

/* Transmit Data */
USARTx->DR = (Data & (uint16_t)0x01FF);
}

int main(void)
{
UART_Initialization();

while(1)
{

for (int i = 0; i <500000; i++)
{}

USART_SendData(USART1, 'F');

}
}

• Weird characters usually come about because of wrong baud rate. Measure with a scope to confirm it is really what you think it is. And if it isn't, then start looking at all the registers involved in setting the baud rate. You will have to dig into the whole clock generation chain for the processor. – mkeith Apr 14 '19 at 23:16
• Yeah, that was exactly that, I just found out that my clock speed was divided by 2, meaning that the actual baudrate was 57600. Thank you very much! – Nathaniel Brochu Apr 15 '19 at 14:08
• It might be helpful to future people if you could answer your own question and accept the answer. It is perfectly OK to accept your own answer if it is the best one (or the only one). – mkeith Apr 15 '19 at 15:28