cancel
Showing results for 
Search instead for 
Did you mean: 

UART

L C
Associate II
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
14 REPLIES 14
AvaTar
Lead
Posted on July 24, 2017 at 08:54

But appear error when compile.

Are we supposed to guess which error, or what ?

L C
Associate II
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

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
L C
Associate II
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

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
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

Posted on July 25, 2017 at 04:50

Use strlen(), make a subroutine that takes a string input, and calls HAL_UART_Transmit() with the appropriate parameters.

On the receive side fill a buffer as you receive characters and parse them, for instance wait until you get the carriage return character and then feed the accumulated string to routines that process that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 25, 2017 at 06:54

Clive One

I have try below code, but not success.

Do you have similar example for me?

BR

0690X00000607ftQAA.png

0690X00000607gNQAQ.png

________________

Attachments :

main.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyMc&d=%2Fa%2F0X0000000b9W%2Fs4Pl0JZYRg1C.ysA.qtWFm51jGGUy9pZF7kB1_sCbQo&asPdf=false
Posted on July 26, 2017 at 13:45

uint8_t readBuff[20]; // Must define a buffer with space in it to hold the data

HAL_UART_Receive(&huart1, (uint8_t *)readBuff, 20, 0x00FF);

If planing on using str functions consider allocating 21 characters so you can place a NUL at the end.

You need to work on your C coding skills.

Sorry I don't have HAL examples, please review subdirectories under the Cube install.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..