2019-01-13 02:55 AM
I'm using the HAL_UART_Receive function for receiving strings and I need to check if the receiving strings matches with the strings that I want to receive.
First I want to create the char for the string in heap:
char *response = (char *)malloc(RN2483_MAX_BUFF);
Then i'm calling the function:
RN2483_response(&huart1, (uint8_t *)response);
This function reads from RX buffer until he reads '\n' character:
// Reads from the RX buffer into response until '\n'
static int RN2483_response(UART_HandleTypeDef *huart, uint8_t *response)
{
int i;
huart->pRxBuffPtr = 0; // delete the last value
// while receiving transfer is not complete
while((*huart->pRxBuffPtr) != '\n')
{
HAL_UART_Receive(&huart1, (uint8_t *)response, RN2483_MAX_BUFF, 1);
huart->pRxBuffPtr++;
i++;
}
if (i <= 0)
return RN2483_ERR_PANIC;
else
return i;
}
How can I get the receiving string in de response character array?
EDIT:
Looks like it's almost working.. The string is just a bit off in the response array:
I have"\nk\r"in response while I receive "ok\r\n"
2019-01-13 05:10 AM
First, avoid using malloc for embedded, just assign at first a static array
The incoming message length is unknown, so the HAL function may not be ideal, if need to use it, receive byte by byte and look for your \n character.
For USART, LL (low layer) maybe more suitable for this mode of console/printf operation.
2019-01-13 05:28 AM
Surely accessing a NULL pointer is not the intended goal?
2019-01-13 05:58 AM
Are you talking about line 1 or 4?