Question
How to "return" HAL_UART_Receive buffer?
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"
