cancel
Showing results for 
Search instead for 
Did you mean: 

USART on the STM32F051

carbolo
Associate II
Posted on October 28, 2013 at 18:00

Hi Folks,

I am a little bit confused about the USART built in in the STM32F051. He is don`t talking to me although I am asking really polite.

This is my init-code:

RCC -> AHBENR |= (RCC_AHBENR_GPIOAEN);

//PA9

GPIOA->OSPEEDR  |= (1UL<< 18);               //MEDIUM SPEED

GPIOA->OTYPER     &= ~(1UL<<9);             //Push-pull

GPIOA->MODER    |= (1UL<<19);                  //AF-Mode

GPIOA->AFR[1]   |= (1UL << 4);                     //AF1 selected

//PA10   

GPIOA->MODER    |= (1UL<<21);                  // AF-Mode

GPIOA->AFR[1]   |= (1UL<<8);                       // AF1 selected

RCC ->APB2ENR |= (1UL<<14);

USART1  -> CR1 = 0x0000000C;                     // enable TX and RX

USART1  -> CR2 = 0x00000000;

USART1  -> CR3 = 0x00000000;             

USART1  -> BRR = 0x00000034;

USART1 -> CR1 |= (1UL << 0);

And this here is my  TX-Routine:

void USART1_tx (char TX_char){

    while (!(USART1 -> ISR  &  ( 1UL << 6))) { __NOP();}        

    

    USART1 -> TDR = TX_char;  

}

Anyone an idea, where the problem is?

#usart #stm32f051
3 REPLIES 3
Posted on October 28, 2013 at 18:22

Anyone an idea, where the problem is?

I should care for register level code, but honestly I don't.

Do you see any data on the scope? Does the baud rate look right?

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/UART%20example%20code%20for%20STM32F0&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=6068]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FUART%20example%20code%20for%20STM32F0&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=6068

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
carbolo
Associate II
Posted on October 28, 2013 at 19:10

Do you see any data on the scope? Does the baud rate look right?

 

No, on the scope is nothing. It seems to be completely dead.

carbolo
Associate II
Posted on October 28, 2013 at 19:51

Problem solved 🙂

add this line to the code and it works.

NVIC_EnableIRQ(USART1_IRQn);