cancel
Showing results for 
Search instead for 
Did you mean: 

UART 1 transmit but the receive data in terminal not same

ismimusyafani
Associate II
Posted on October 01, 2015 at 04:52

void UART1_Config(int baudrate){

    __USART1_CLK_ENABLE();

    

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

  GPIO_InitStruct.Pin = (GPIO_PIN_6 | GPIO_PIN_7);

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

    GPIO_InitStruct.Alternate = GPIO_AF7_USART1;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

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

    

    /*♯♯-1- Configure the UART peripheral ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

  /* Put the USART peripheral in the Asynchronous mode (UART Mode) */

  /* UART1 configured as follow:

      - Word Length = 8 Bits

      - Stop Bit = One Stop bit

      - Parity = ODD parity

      - BaudRate = 9600 baud

      - Hardware flow control disabled (RTS and CTS signals) */

  UartHandle.Instance          = USART1; //enable uart clock

  UartHandle.Init.BaudRate     = baudrate;

  UartHandle.Init.WordLength   = UART_WORDLENGTH_8B;

  UartHandle.Init.StopBits     = UART_STOPBITS_1;

  UartHandle.Init.Parity       = UART_PARITY_NONE;

  UartHandle.Init.HwFlowCtl    = UART_HWCONTROL_NONE;

  UartHandle.Init.Mode         = UART_MODE_TX_RX;

  UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;

    

   HAL_UART_Init(&UartHandle);

}

and this is my function to send data .

void SendByte1(unsigned char a) {

    

    while ((USART1->SR & USART_SR_TXE) == 0);

    USART1 -> DR = a ;

    while ((USART1->SR & USART_SR_TXE) == 0);

}

why, if i SendData1(0xFF), in the hyperterminal will receive F0 and always different with thw transmit data.

#stm32halusart
3 REPLIES 3
Amel NASRI
ST Employee
Posted on October 01, 2015 at 10:29

Hi musyafani,

Did you tried using the HAL function: HAL_UART_Transmit? What do you get as result in this case?

-Mayla-

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.

ismimusyafani
Associate II
Posted on October 01, 2015 at 19:37

can you show me how to use the hal function with HAL_Uart_Transmit();

Amel NASRI
ST Employee
Posted on October 07, 2015 at 13:49

Hi musyafani

Have a look to any UART example available in STM32CubeF4 (I don't know which parts are you using exactly).

There are ones under STM32Cube_FW_F4_V1.8.0\Projects\STM32F4-Discovery\Examples\UART.

-Mayla-

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.