cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 USART2 do not receive

Antos.Jiri
Associate II
Posted on June 08, 2016 at 15:51

Hello,

I have configured USART2 to communicate as RS422. Rx is connected to PA.3, Tx to PD.5. I need baudrate 921.600 Baud. There is no problem send anything one or more bytes. I can not receive anything from Rx (PA.3) pin, but when I sent anything, RXNE pin is set toghether with IDLE and ORE. DR register contain 0x7F. I sent 0x55. Situation is same if I have or not data on Rx line (0x55 from the other micro).

Is there somebody who could give me an advice, where may be a problem (where is devil lie). Thanks

Jiri

#no-hablo-hal
8 REPLIES 8
Posted on June 08, 2016 at 16:15

Provide a complete/concise example of the code that should demonstrate this. I've dealt with a lot of USART issues, but not looking to play 20 question to pull out the detail.

How does the configuration for using a differential pair for each channel alter the configuration of the USART?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Antos.Jiri
Associate II
Posted on June 09, 2016 at 06:52

Hi, there is my code. Rx and Tx wires are connected to ISL3176EIUZ driver.

// -----------------------------------------------------------------------------------

// copy from the hal.h and hal.c

// RS422 TXD

#define HAL_422TxPort                GPIOD

#define HAL_422TxPin                 GPIO_PIN_5

#define HAL_422TxAf                  GPIO_AF7_USART2

// RS422 RXD

#define HAL_422RxPort                GPIOA

#define HAL_422RxPin                 GPIO_PIN_3

#define HAL_422RxAf                  GPIO_AF7_USART2

// RS422 EnRx

#define HAL_422EnRxPort              GPIOD

#define HAL_422EnRxPin               GPIO_PIN_3

// RS422 EnTx

#define HAL_422EnTxPort              GPIOD

#define HAL_422EnTxPin               GPIO_PIN_4

// enable clocks are on the different place

  // RS422_TXD

  GPIO_InitStructure.Pin       = HAL_422TxPin;

  GPIO_InitStructure.Alternate = HAL_422TxAf;

  HAL_GPIO_Init(HAL_422TxPort, &GPIO_InitStructure);

  // 422_RXD

  GPIO_InitStructure.Pin       = HAL_422RxPin;

  GPIO_InitStructure.Alternate = HAL_422RxAf;

  HAL_GPIO_Init(HAL_422RxPort, &GPIO_InitStructure);

    

  // outputs

    HAL_422EnRxPort->BSRRH         = HAL_422EnRxPin;         // set to 0 ... enabled

    HAL_422EnTxPort->BSRRH         = HAL_422EnTxPin;         // set to 0 ... dissabled

  GPIO_InitStructure.Mode   = GPIO_MODE_OUTPUT_PP;

  GPIO_InitStructure.Speed  = GPIO_SPEED_HIGH;

  GPIO_InitStructure.Pull   = GPIO_NOPULL;

  GPIO_InitStructure.Pin    = HAL_422EnRxPin;

  HAL_GPIO_Init(HAL_422EnRxPort, &GPIO_InitStructure);

  GPIO_InitStructure.Pin    = HAL_422EnTxPin;

  HAL_GPIO_Init(HAL_422EnTxPort, &GPIO_InitStructure);

// -----------------------------------------------------------------------------------

  USART_HandleTypeDef husart2;

    

/* USART2 init function */

void MX_USART2_UART_Init(void)

{

  __USART2_CLK_ENABLE();

    

  husart2.Instance = USART2;

  husart2.Init.BaudRate = 921600; //2457600;

  husart2.Init.WordLength = USART_WORDLENGTH_8B;

  husart2.Init.StopBits = USART_STOPBITS_1;

  husart2.Init.Parity = USART_PARITY_NONE;

  husart2.Init.Mode = USART_MODE_TX_RX;

//  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

//  huart2.Init.OverSampling = UART_OVERSAMPLING_16;

    husart2.Init.CLKPhase = USART_PHASE_1EDGE;

    husart2.Init.CLKPolarity = USART_POLARITY_LOW;

    husart2.Init.CLKLastBit = USART_LASTBIT_DISABLE;

  HAL_USART_Init(&husart2);

}

// -----------------------------------------------------------------------------------

    MX_USART2_UART_Init();

    HAL_422EnTxPort->BSRRL         = HAL_422EnTxPin;         // set to 1 ... enabled

    while (1) {

        if ((USART2->SR & USART_FLAG_RXNE) != 0) {

            RxBuf2[0] = USART2->DR;

            USART2->DR = 0xAA;

            while ((USART2->SR & USART_FLAG_TXE) == 0) {osThreadYield();}

            USART2->DR = RxBuf2[0];

            while ((USART2->SR & USART_FLAG_TXE) == 0) {osThreadYield();}

        }

        //HAL_USART_Transmit(&husart2, RxBuf2, 1, 1);

        //osThreadYield();

        USART2->DR = 0x55;

        while ((USART2->SR & USART_FLAG_TC) == 0) {osThreadYield();}

        osDelay(1);

            

    }  

that's all

Jiri

Antos.Jiri
Associate II
Posted on June 09, 2016 at 07:09

Hi. There are two screenshots from osciloscope.

With active and with calm Rx line.

On the othere side of line is STM32F429 and same driver ISL3176 connected to USART6. There is no problem send or receive datas.

Jiri

________________

Attachments :

Active_Rx.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0kf&d=%2Fa%2F0X0000000bdF%2FfUOkAduaJ4_XXBgxdzzH05oiv0t9Am3BeHrHuy.ZFrM&asPdf=false

Calm_Rx.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0ka&d=%2Fa%2F0X0000000bdG%2Fp7_or0Ad2pV1xx6L_0tyzNsIeN8fX2syQahDmmgK8io&asPdf=false
Antos.Jiri
Associate II
Posted on June 09, 2016 at 08:56

If Rx does not react on real incoming data, and does react on Tx-ing, it then does not matter what is connected and what are the waveforms, isn't it.

Post the USART registers' content.

JW

Posted on June 13, 2016 at 11:11

You have USART_CR2.CLKEN set. That implies synchronous mode.

JW
Antos.Jiri
Associate II
Posted on June 15, 2016 at 14:54

Thank you Mr. Waclavek Jan

Reason was a using of HAL_USART library, but there is necessary to use HAL_UART library. Thank for help.

Jiri