有人可以解释为什么我只能收到带有USART中断的13个字符吗?我使用' n'来检测字符串的结尾。
- #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 *)"
", strlen("
"));
- 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);
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>