AnsweredAssumed Answered

USART2 Init STM32F101

Question asked by maurosmartins on Feb 20, 2017
Latest reply on Feb 20, 2017 by Clive One

Hello all,

I'm trying to configure USART on a STM32F101RB micrcontroller with Atollic True Studio.

the uC clock is configured as external clock (8Mhz) divided by 2 and pll'ed by 9 to a total 36Mhz.

I'm using the HAL to initialize the microcontroller, but so far I hadn't had success. I know the hw is working ok because setting that port with mikroC... it works.

normal usart initialization


static void MX_USART2_UART_Init(void){

huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)

Clock for porta has already been enabled by calling:


and finally the Hw initialization is as follows:



void HAL_UART_MspInit(UART_HandleTypeDef* huart){

GPIO_InitTypeDef GPIO_InitStruct;



/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);


with this I've tryed to send the eternal "Hello World" as follows:


char msg[] = "Hello World!\n\r";
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), 0xFFFF);


but no success, I've even checked if alternative pins were enabled, but, they were not.


any ideas of what can be wrong?


thanks in advanced,
Best regards Mauro.