Skip to main content
Scott Shan
Associate
November 10, 2017
Question

STM32F302R8 MCU UART2 Tx Incompleted

  • November 10, 2017
  • 2 replies
  • 1303 views
Posted on November 10, 2017 at 05:42

Hi,

I used STM32F103 MCU before and was new for STM32F3x MCU. My stm32f103 codes was migrated to stm32f302 codes for stm32f302r8 MCU.The code problem is that after power on, MCU turned on LED normally and printed out ''0123456789'' only (full string should be '1234567890'), and then got stuck. Attached please find my stm32f302 codes. Can anyone expert help me to fix this issue? Thanks in advance.

0690X0000060PCNQA2.png

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    November 10, 2017
    Posted on November 10, 2017 at 18:00

    Use TXE to determine the DR is EMPTY before stuffing data, don't use TC for that purpose.

    /*********************************************************************

    * @brief Print character for USART

    */

    void USART_PrintChar(USART_TypeDef* USARTx, u8 ch)

    {

    while (USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET); // empty, ready for new data

    USARTx->TDR = ch; //USARTx->DR = ch;

    }

    /*********************************************************************

    * @brief Print string for USART

    */

    void USART_PrintStr(USART_TypeDef* USARTx, char *str)

    {

    while(*str)

    USART_PrintChar(USARTx, *str++);

    while (USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET); // Wait complete if must

    }

    /*********************************************************************

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Scott Shan
    Associate
    November 11, 2017
    Posted on November 11, 2017 at 10:39

    Many Thanks for the replay.

    I found the major issue is inside routine '

    NVIC_Configuration()'.

    =================================

    void NVIC_Configuration(void)

    {

    NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x6000); 

    <== I uploaded firmware which started from memory 0x00 (without bootloader), so should remove this line.

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

    ....

    }

    =================================