2017-07-23 11:08 PM
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
2017-07-23 11:54 PM
But appear error when compile.
Are we supposed to guess which error, or what ?
2017-07-24 09:43 AM
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
2017-07-24 09:54 AM
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 &
2017-07-24 05:42 PM
Dear ALL
The screen dump with error message and source code are attached.
Please take a look and let me know your comment.
BR
2017-07-24 07:46 PM
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 &
2017-07-24 08:59 PM
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
orHAL_USART_TransmitReceive_IT
?Please let me know your comment.
BR
2017-07-24 09:50 PM
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.
2017-07-24 11:54 PM
Clive One
I have try below code, but not success.
Do you have similar example for me?
BR
________________ 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=false2017-07-26 06:45 AM
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.