Skip to main content
Carter Lee
Associate III
September 11, 2017
Solved

Should USARTx->BRR have to re-calculate ?

  • September 11, 2017
  • 11 replies
  • 1657 views
Posted on September 11, 2017 at 16:33

Hi,

Now I'm trying to implement UART function as the below,

But the problem is keep showing in RS232 Tool.

I'm just referring fully reference posting such as

https://community.st.com/thread/19577?commentID=48791#comment

There's no miss match. But I don't know what is the problem and how to resolve this.

Could you please any advice to resolve this problem?

I guess one thing is there's noUSARTx->BRR declaration.

Is this possible way to happen the problem??

0690X000006044uQAA.jpg

USART_InitTypeDef USART_InitStructure;

int putcharx(int ch)

{

while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

USART_SendData(USART1, (uint8_t)ch);

return ch;

}

int main(void)

{

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

//UART////////////////////////////////////////////////////////////////////////

/*-------------------------- GPIO Configuration ----------------------------*/

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Connect USART pins to AF */

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); // USART1_TX

GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // USART1_RX

USART_InitStructure.USART_BaudRate = 9600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, ENABLE);

/////////////////////////////////////////////////////////////////////////////////

while (1)

{

USART_SendData(USART1, 0x49); // Send 'I' //TEST 2

}

In case TEST 1 and TEST2 have the same output result as the below image.

0690X000006041cQAA.jpg

What am I supposed to do to resolve this problem?

should I have to calculate about

USARTx->BRR

?

Note: this post was migrated and contained many threaded conversations, some content may be missing.
    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    Posted on September 12, 2017 at 16:34

    See here, where you were told about removing SB15

    https://community.st.com/0D50X00009XkXNtSAN

    11 replies

    Tesla DeLorean
    Guru
    September 11, 2017
    Posted on September 11, 2017 at 16:50

    Can we *PLEASE* keep all your USART related adventures in one thread? Your audience here is limited.

    You would need to make sure HSE_VALUE is correctly defined for the board, perhaps in stm32f4xx_conf.h and be 8000000 and not 25000000. Check also that system_stm32f4xx.c configures the PLL with the expectation of an 8 MHz crystal and not a 25 MHz one.

    Unless you change the bus speeds dynamically you shouldn't need to revisit USART->BRR

    Send an 0x55 data pattern and confirm the bit timing with a scope. Don't send data to the register unless TXE is asserted, you'll just garble things.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Carter Lee
    Associate III
    September 12, 2017
    Posted on September 12, 2017 at 16:16

    Clive, I'm struggling to receive data from PC with code below.

    Sending data from STM32 board to PC is working good.

    But receiving from PC has a problem.

    The below image ,  I just prove the PA10 while sending data.

    0690X000006041mQAA.jpg

    I'm not sure but would you please check this configuration?

    void SendCharUSART1(char ch){

    // Wait until TXE is set

    while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)

    {

    }

    USART_SendData(USART1, ch);

    // Wait until the end of transmit

    while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)

    {

    }

    }

    char GetCharUSART1(void){

    char ch;

    // Wait until the USART1 Receive Data Register is not empty

    while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)

    {

    }

    ch = (USART_ReceiveData(USART1) & 0xFF);

    return ch;

    }

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); // USART1_TX

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // USART1_RX

    USART_InitStructure.USART_BaudRate = 9600;

    USART_InitStructure.USART_WordLength = USART_WordLength_8b;

    USART_InitStructure.USART_StopBits = USART_StopBits_1;

    USART_InitStructure.USART_Parity = USART_Parity_No;

    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

    USART_Init(USART1, &USART_InitStructure);

    USART_Cmd(USART1, ENABLE);

    /////////////////////////////////////////////////////////////////////////////////

    SYSCFG_EXTILineConfig(0x0,0);

    ...

    SendCharUSART1(0x0D);

    SendCharUSART1(0x0A);

    SendCharUSART1('U');

    SendCharUSART1('S');

    SendCharUSART1('A');

    SendCharUSART1('R');

    SendCharUSART1('T');

    SendCharUSART1('1');

    SendCharUSART1('>');

    // Get and echo USART1

    ch = GetCharUSART1();

    while (ch != 0x0D) {

    SendCharUSART1(ch);

    ch = GetCharUSART1();

    }

    What am I missing?

    Currently, stuck in here  while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)  

    during sending the data from PC to eval board.

    0690X00000608CJQAY.png
    Tesla DeLorean
    Guru
    September 12, 2017
    Posted on September 12, 2017 at 16:31

    So you show me a static signal on the USART1_RX and ask why it receives nothing?

    Is this pin clashing with the VCP? Did you disconnect the ST-LINK's USART from the STM32F429? Make sure SB15 is *REMOVED*

    0690X00000603vvQAA.jpg
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..