2020-09-17 01:31 AM
Hi everyone.
I am sending string data from PC and I want it get with UART of STM32F1xx but as you know I can only have 1 character.
For example I am sending "234" as a string from PC, but I can see only ascii character of only 2 (ascii code of 2 is 50).
I can transmit data as a string on UART. But I can not receive.
Do you know anyone solution method of this problem?
uint8_t UartRxData[10];
//(... 234 comes from PC as a string...)
HAL_UART_Receive_IT(&huart2, (uint8_t*)&UartRxData, 1);
//(result is 50... mean is ascii code of 2)
Thanks and regards
2020-09-17 04:44 AM
Your request is 1 byte with: HAL_UART_Receive_IT(&huart2, (uint8_t*)&UartRxData, 1);
So you receive 1 byte...
By the way UartRxData is an array so no need of cast : HAL_UART_Receive_IT (& huart2, UartRxData, 3) ;
2020-09-17 04:47 AM
Thank you for you answer but not interested with it.
If you give 3 there then 234 comes as 2,3,4 and writes 50,51,52.
I am trying to get 234 as a character in 1 byte.
2020-09-17 10:18 AM
If you send a string "234" you will receive the string "234" !
If you want the number 234 then convert the received string to a number:
HAL_UART_Receive_IT (& huart2, UartRxData, 3) ;
UartRxData [3] = 0 ;
uint8_t xx = (uint8_t) atoi ((const char *) UartRxData) ;