cancel
Showing results for 
Search instead for 
Did you mean: 

UART4 RX Signal level

Kim.Andy
Associate III

I use the UART4 like the following initialization.

void uart4_configuration(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    /* enable usart clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
 
 
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
 
 
    // Configure USART Tx as alternate function
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;            //GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Pin = RS485AXM_TX_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(RS485AXM_COM_PORT, &GPIO_InitStructure);
 
    // Configure USART Rx as alternate function
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;            //GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Pin = RS485AXM_RX_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(RS485AXM_COM_PORT, &GPIO_InitStructure);
 
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
 
 
    USART_StructInit(&USART_InitStructure);
    USART_InitStructure.USART_BaudRate = 9600;
    USART_Init(UART4, &USART_InitStructure);
 
    USART_Cmd(UART4, ENABLE);
 
    NVIC_EnableIRQ(UART4_IRQn);
}

The Rx signal level is abnormal like the following.

0690X00000DYODdQAP.jpg

The low level is not the zero(ground) level.

But the Tx level is ok like the followings.

0690X00000DYODiQAP.jpg

Although I detach the RX Pin from the PCB Board, and tie with the TX Pin,

RX/TX Pin level is like the abnormal level(the first image)

Is the initialization is wrong?

Thanks

2 REPLIES 2
Olivier GALLIEN
ST Employee

Hi @AK.12.26im​ 

In order to reach faster the relevant community could you please add further information about your context ?

chip, board, application ...

Thanks

Olivier

Olivier GALLIEN
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
PatrickF
ST Employee

Sound like your usage of GPIO_Init() is wrong, you miss the GPIO_InitStruct.Alternate setting and GPIO_PinAFConfig() does not exist in CubeMP1 drivers.

Here is an example of UART AF mux setting generated by CubeMx:

    /**UART4 GPIO Configuration    
    PD1     ------> UART4_TX
    PH14     ------> UART4_RX 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_14;
    GPIO_InitStruct.Mode = GPIO_MODE_AF;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
    HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.