FR802x串口接收超时
-
FR802x支持串口超时判断,使用方法是怎么样的?
-
此回复已被删除!
-
# define AT_RECV_MAX_LEN 513 static void app_at_recv_c(uint8_t *rx_buff,uint16_t rx_length) { if((memcmp(at_recv_buffer,"AT#",3)==0)||(memcmp(at_recv_buffer,"AT+",3)==0)) { uint16_t cmd_len=rx_length-3; struct app_task_event *event; event = app_task_event_alloc(APP_TASK_EVENT_AT_CMD, cmd_len, false); if(event) { memcpy(event->param, &at_recv_buffer[3], cmd_len); app_task_event_post(event, false); } } else { struct app_task_event *event; event = app_task_event_alloc(APP_TASK_EVENT_SPEED, at_recv_index, false); if(event) { memcpy(event->param, at_recv_buffer, at_recv_index); app_task_event_post(event, false); } } memset(at_recv_buffer,0,AT_RECV_MAX_LEN); at_recv_index = 0; } extern USART_HandleTypeDef log_usart; __RAM_CODE void USART2_IRQHandler(void) { if((__USART_GET_INT_STATUS(USART2, USART_INT_RX)) || (__USART_GET_INT_STATUS(USART2, USART_INT_RFTO))) { if(log_usart.Init.DataLength == USART_DATA_LENGTH_9BIT) { /*Rx ready */ while(__USART_GET_SR_STATUS(USART2, USART_STATUS_DR)) { (*(uint16_t*)log_usart.p_RxData) = USART2->DR; log_usart.p_RxData += sizeof(uint16_t); log_usart.u32_RxCount++; } } else { /* Rx ready */ while(__USART_GET_SR_STATUS(USART2, USART_STATUS_DR)) { at_recv_buffer[at_recv_index++] = USART2->DR; if(at_recv_index>=AT_RECV_MAX_LEN) { app_at_recv_c(&at_recv_buffer[0],at_recv_index); } } } }/* Receiver Timeout */ if(__USART_GET_INT_STATUS(USART2, USART_INT_RTO)) { __USART_CLEAN_INT_STATUS(USART2, USART_INT_RTO); at_recv_buffer[at_recv_index++] = USART2->DR; // for(uint8_t i=0;i<at_recv_index;i++) // { // printf("%c ",at_recv_buffer[i]); // } // printf("Packet Len = %d\r\n", at_recv_index); /*这里处理完整的数据包*/ app_at_recv_c(&at_recv_buffer[0],at_recv_index); } }
-
