F00007usart Data Processing Program
Resolution: usart automatically sends data solutions on the Cortex-M4. 1. usart is interrupted too quickly. The data has not been processed. The usart interrupt overwrites the unprocessed data. Data loss. 2. This program needs to process the data of four usart ports in main, so that the error probability is greater. The following solution is proposed: 1. specify the length of each completed data entry. The step length exceeds 256 bytes. Second: we define the ending table of the data as the last three digits of the data, and FFFFFF third: define a global data, it is a three-dimensional array. The data is used to store data sent from four usart ports. Uint8_t usart_data [4] [5] [256]; The following explains why to define a three-dimensional array: The first subscript 4: It is used to accept data from different usart ports. The second subscript 5: It indicates that the maximum number of data records that can be cached by each usart is 5. The third subscript 256: it indicates that a maximum of 256 bytes of data can be saved. The following is how the program is implemented. Define the following variables: 1. Accept the definition of usart data buffer. It is a global three-dimensional data uint8_t usart_data [4] [5] [256] = {0}; 2: records the number of data records received by each usart port. Uint8_t data_count [4] = {0}; 3. record the number of currently accepted data. Uint8_t data_len [4] = {0}; 4: used to record the number of errors. Uint8_t error_count = 0; void UART_DATA_handle (uint8_t route) {if (data_count [route] <5) {if (usart_data [route] [data_count [route] [data_len [route]-3] = 0xFF) & (usart_data [route] [data_count [route] [data_len [route]-2] = 0xFF) & (usart_data [route] [data_count [route] [data_len [route]-1] = 0xFF )) {if (usart_data [route] [data_count [route] [0] = data_len [route]) {data_count [route] ++; data_len [route] = 0; if (data_count [ro Ute]> 5) {data_count [route] = 0;} else {error_count ++ ;}}}} void usart=irqhandler (void) {if (USART_GetITStatus (USART1, USART_IT_RXNE )! = RESET) {USART_ClearITPendingBit (USART1, USART_IT_RXNE); usart_data [0] [data_cout [0] [data_len [0] ++] = USART_Rece_Data (USART1 ); if (data_len [0]> 2) {usart_data_route (0) ;}}return;} void USART2_IRQHANDLER (void) {if (USART_GetITStatus (USART2, USART_IT_RXNE )! = RESET) {USART_ClearITPendingBit (USART2, USART_IT_RXNE); usart_data [1] [data_cout [1] [data_len [1] ++] = USART_Rece_Data (USART2 ); if (data_len [1]> 2) {usart_data_route (1) ;}}return;} void USART3_IRQHANDLER (void) {if (USART_GetITStatus (USART3, USART_IT_RXNE )! = RESET) {USART_ClearITPendingBit (USART3, USART_IT_RXNE); usart_data [2] [data_cout [2] [data_len [2] ++] = USART_Rece_Data (USART3 ); if (data_len [2]> 2) {usart_data_route (2) ;}}return;} void USART4_IRQHANDLER (void) {if (USART_GetITStatus (USART4, USART_IT_RXNE )! = RESET) {USART_ClearITPendingBit (USART4, USART_IT_RXNE); usart_data [3] [data_cout [3] [data_len [3] ++] = USART_Rece_Data (USART4 ); if (data_len [3]> 2) {usart_data_route (3) ;}} return ;} /***** main *******/uint8_t tmp [512] = {0}; static _ INLINE void process_usartdata (uint8_t * tmpdata, uint8_t * usartdata, char * usart_format, int flag) {int tmp = 0, count = 0, I = 0; memset (tmpdata, 0x00,512); printf (usart_format, flag ); for (I = 0; I
0) {process_usartdata (tmp, usart_data [I] [data_count [I], "usart: % d", I); data_count [I] --;} if (data_count [I]> 5) {data_count [I] = 0 ;}}}........}