AnsweredAssumed Answered

STM32F407 UART4 Problem

Question asked by li.kun.002 on Dec 3, 2015
Latest reply on Dec 4, 2015 by li.kun.002
Hi,

I am using STM32F407 UART port to read data from a device with baudrate 115200. However, I cannot obtained the desired data. The data I obtained is decoded as follow:

0x 94 86 b7 f3 94 86 b7 f3
0x 94 86 b7 f3 94 86 bc c2
0x 94 86 ed f5 94 86 bc c2
0x 94 86 b7 f3 94 86 bc c2
0x 94 86 81 bf 94 86 ad f5
0x 94 86 bc c2 94 86 86 aa
0x 94 86 da be 94 ...
...
...

While the desired data should be decoded as follow (from linux picocom/cutecom with configuration of 115200, 8N1, no parity, no hardware control):

00012750: 54 06 31 66 54 06 31 66 

00012760: 54 06 2c 35 54 06 2c 35

00012770: 54 06 2c 35 54 06 2c 35

00012780: 54 06 22 1f 54 06 1d a2

00012790: 54 06 18 b9 54 06 2c 35

000127a0: 54 06 1d a2 54 06 31 66

000127b0: 54 06 36 73 54 06 22 1f 

000127c0: 54 06 2c 35 54 06 2c 35 

000127d0: 54 06 27 04 54 06 2c 35

000127e0: 54 06 2c 35 54 06 27 04

000127f0: 54 06 2c 35 54 06 2c 35  

Actually I have found the wrong pattern as: 0x54 is the first byte transfered and is always decoded as 0x94 or 0xd4, the following bytes are also wrong due to some wrongly decoded bits.

 

Below is my configuration code inside the STM32F407:

 

void trone_config(void)
{
    valid_data = 0;
    /* Configures the nested vectored interrupt controller. */
    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable the USARTx Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    /* Enable the USART clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
    /* Enable GPIO clocks */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

    /* Connect UART pins to AF7 */
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);

    GPIO_InitTypeDef GPIO_InitStructure_Serial2;
    GPIO_InitStructure_Serial2.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure_Serial2.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure_Serial2.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure_Serial2.GPIO_PuPd = GPIO_PuPd_UP;

    /* USART RX pin configuration */
    GPIO_InitStructure_Serial2.GPIO_Pin = GPIO_Pin_11;
    GPIO_Init(GPIOC, &GPIO_InitStructure_Serial2);

    USART_InitTypeDef USART_InitStructure;

    USART_InitStructure.USART_BaudRate = 115200;
    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;

    /* Configure the UART4 */
    USART_Init(UART4, &USART_InitStructure);

    /* Enable UART4 interrupt */
    USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);

    USART_Cmd(UART4, ENABLE);

}

void UART4_IRQHandler(void)
{
    if (USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)
    {
        /* Read one byte from the receive data register */
        uint8_t data = (USART_ReceiveData(UART4));
        if(testflag<100)
            testbuff[testflag++] = data;
        else
            testflag = 0;
    }
}

I have debugged the board for quite a few days and still get the problem. I think I have configured the UART port in STM32F407 as indicated: baud rate 115200, word length 8 bits, 1 stop bit, no parity. Please help me out of this!

Thank you very much!!
Regards,
Kun

Outcomes