Skip to main content
L C
Associate III
July 24, 2017
Question

UART

  • July 24, 2017
  • 2 replies
  • 7374 views
Posted on July 24, 2017 at 08:08

Hi!

I am study UART to communicate with PC.

My target is use PC like a terminal to input AND out message to STM32.

My code is using HAL library.

I want to operate code like below.

**************************************

ch = ''UART test\r\n'';

HAL_UART_Transmit(&huart1,(uint8_t *)&ch, 10, 0xFFFF);

***************************

But appear error when compile.

Please let me know your comment.

BR

0690X00000607foQAA.png
    This topic has been closed for replies.

    2 replies

    AvaTar
    Senior III
    July 24, 2017
    Posted on July 24, 2017 at 08:54

    But appear error when compile.

    Are we supposed to guess which error, or what ?

    L C
    L CAuthor
    Associate III
    July 24, 2017
    Posted on July 24, 2017 at 16:43

    Sorry, Just be calling for meeting when posting.

    The error message is 'Error[Pe144]: a value of type 'char *' cannot be used to initialize an entity of type 'uint8_t' E:\STM32\Project\UART\Src\main.c 83 '

    I know that the data type is different.

    But how do I do to convert it.

    BR

    Tesla DeLorean
    Guru
    July 24, 2017
    Posted on July 24, 2017 at 16:54

    So which line is 83? Please present problems in clear and complete fashion

    char *ch; // It is a char pointer, right?

    ch = 'UART test\r\n';

    HAL_UART_Transmit(&huart1,(uint8_t *)ch, 10, 0xFFFF); // It is a pointer, you don't need the address of the pointer, lose the &

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    L C
    L CAuthor
    Associate III
    July 25, 2017
    Posted on July 25, 2017 at 02:42

    Dear ALL

    The screen dump with error message and source code are attached.

    Please take a look and let me know your comment.

    BR

    Tesla DeLorean
    Guru
    July 25, 2017
    Posted on July 25, 2017 at 02:46

    It is pointer to multiple chars, you can't define it as 'char ch' needs to be 'char *ch'

    char *ch

    = 'UART test\r\n'; // It is a pointer

    HAL_UART_Transmit(&huart1,(uint8_t *)ch, 10, 0xFFFF); // It is a pointer, you don't need the address of the pointer, lose the &

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    L C
    L CAuthor
    Associate III
    July 25, 2017
    Posted on July 25, 2017 at 03:59

    Clive One

    Thanks for your help. It is work fine.

    Clive One & ALL

    My target is using UART like a terminal for display(output) & input to STM32.

    To refer my provided code, the send out data size is necessary predefined.

    HAL_UART_Transmit(&huart1,(uint8_t *)ch,

    10

    , 0xFFFF)

    In application, the message size is not fixed. I think it is simple example only.

    If predefined it bigger, it will occupy memory all the time. 

    How can I to optimize it?

    For receive data, I see some example using time window to wait input data from UART port.

    This method need CPU ask & wait input data. It will consume CPU time resource.

    If using interrupt method, how can I to receive ALL data/message and NOT a character only?

    Finally, shall we use simple transmit function(

    HAL_USART_Transmit

    ) AND interrupt receive function(

    HAL_USART_Receive_IT

    ) together?

    Another side I should use 

    HAL_USART_TransmitReceive

    or 

    HAL_USART_TransmitReceive_IT

    ?

    Please let me know your comment.

    BR