AnsweredAssumed Answered

Simple UART Tx. Using HY-mini STM32V eval. kit.

Question asked by Phataas on Dec 10, 2012
Latest reply on Dec 13, 2012 by Phataas
I have been trying to get UART working for the last couple of days with no luck. I have tested an UART example code and it worked. So clearly there is something I am missing. I would really appreciate any hints, tips, feedbacks etc. Here is the code:

#include "stm32f10x.h"
 
int main(void)
{
    //Inits.
    RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_USART1EN | RCC_APB2ENR_AFIOEN);
    GPIOA->CRH |= (GPIO_CRH_CNF9_1 | GPIO_CRH_MODE9_1 | GPIO_CRH_MODE9_0);
    USART1->CR2 &= (~USART_CR2_CPOL | ~USART_CR2_CPHA | ~USART_CR2_CLKEN | ~USART_CR2_LBCL | ~USART_CR2_STOP);
    USART1->CR1 &= (~USART_CR1_M | ~USART_CR1_PCE | ~USART_CR1_PS | ~USART_CR1_TE | ~USART_CR1_RE);
    USART1->CR1 |= USART_CR1_TE;
    USART1->CR3 &= (~USART_CR3_CTSE | ~USART_CR3_RTSE);
    USART1->BRR = ( (0x0034 << 4) | (0x0001) );     //9600 @8MHz
    //USART1->BRR = ( (0x0004 << 4) | (0x0005) );       //115200 @8MHz
    //USART1->BRR = ( (0x0027 << 4) | (0x0001) );       //115200 @72MHz
    USART1->CR1 |= USART_CR1_UE;
     
    while(1)
    {
        USART1->DR = (uint8_t) 0xAA;
        while(! (USART1->CR1 & USART_SR_TC) );
        //while(! (USART1->CR1 & USART_SR_TXE) );
         
    }
}

Outcomes