could someone explain why i can only receive 13 chars with USART interrupt? I use '\n' to detect the end of string.
#define BUFFER_SIZE 100
char receive_buffer[BUFFER_SIZE];
char receive_data;
int receive_index = NULL;
int data_ready_index = NULL;
void USART2_receive(void const * argument){
for(;;){
if(data_ready_index == 1){
HAL_UART_Transmit_IT(&huart2, (uint8_t *)"Received data: ", strlen("Received data: "));
HAL_Delay(50);
HAL_UART_Transmit_IT(&huart2, (uint8_t *)receive_buffer, strlen(receive_buffer));
memset(receive_buffer, NULL, sizeof(receive_buffer));
HAL_Delay(50);
HAL_UART_Transmit_IT(&huart2, (uint8_t *)"\r\n", strlen("\r\n"));
data_ready_index = NULL;
}
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if (huart->Instance == USART2){
if (receive_data != 13){
receive_buffer[receive_index++]=receive_data;
}else{
receive_index = NULL;
data_ready_index = 1;
// Received data ready to be processed
}
}
}
void USART2_IRQHandler(void){
HAL_UART_IRQHandler(&huart2);
HAL_UART_Receive_IT(&huart2, (uint8_t *) &receive_data, 1);
}
\n
but your code is checking for\r
which is 13 and you only process 13 bytes, but then why isstrlen
giving more than 13 and sends some 0x00 bytes with them (<0>) - the message you get back is the length of the transmitted message just the content of the last 3 bytes is wrong. \$\endgroup\$