I'm trying to enable the USART1 periferial on Stm32F103 MCU. My code looks like this:

#include "stm32f10x.h"

void UARTInit(void);
void GPIOInit(void);
USART_InitTypeDef USART_1;

int main()
    USART_SendData(USART1, 0x12);
    while (1)


void UARTInit()
    USART_Init(USART1, &USART_1);

void GPIOInit()
    GPIOA -> CRH |= GPIO_CRH_CNF9_1;

    GPIOA->CRH  &= ~GPIO_CRH_CNF10; 
    GPIOA->CRH  |= GPIO_CRH_CNF10_0;
    GPIOA->CRH  &= ~GPIO_CRH_MODE10_1;

As you can see, i firstly enable clock for USART1 and after that initialize it. Before executing this: RCC ->APB2ENR |= RCC_APB2ENR_USART1EN all bits in USART registers are set to 0 (see first attached image). But when clock is enabled, TC and TXE bits are set to 1, even when USART is not enabled yet. (see second screen). First screen

Second screen

So, if you have any ideas why ths happens - i'll be very appreciate for yours help. Thanks.

  • \$\begingroup\$ I don't see anything strange, due to reference manual page 822 those bits are set by the hardware and they are likely to indicate current peripheral state - USART is ready to transmit data. Please, clarify what are you asking and what is your specific problem. \$\endgroup\$ – Vadimchik Dec 1 '17 at 15:46
  • \$\begingroup\$ I read that manual. But, please, notice that USART is not enabled, not configured - so, how this bits can be set? Also, no transmit was done at all. So, my question sounds like: what is the reason, that this bits are set to 1 after clock enable for USART? \$\endgroup\$ – Majestry Dec 1 '17 at 15:56

What you see is the normal behavior of the USART peripheral of the STM32.

Those bits are set independently of the UE bit in the CR1 register. They just indicate, that the transmit buffer is empty (TXE) and the transfer shift register is empty (TC).

Which is true (because you just enabled the clock, nothing can be in there) and usually not a problem - just don't enable the TXE or TC interrupt before the UE bit is set, otherwise your interrupt will probably not do what you'd like it to do.

The UE-bit description reads:

When this bit is cleared the USART prescalers and outputs are stopped and the end of the current byte transfer in order to reduce power consumption. This bit is set and cleared by software.

0: USART prescaler and outputs disabled

1: USART enabled

So while it might sound a bit like a complete USART enable bit, it just works on the prescaler and outputs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.