STM32CUBEMX_DMA串口空闲中断接收+接收发送缓冲区

2023-10-13 14:52

本文主要是介绍STM32CUBEMX_DMA串口空闲中断接收+接收发送缓冲区,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

STM32CUBEMX_DMA串口空闲中断接收+接收发送缓冲区

前言:
我了解的串口接收指令的方式有:在这里插入图片描述

1、接收数据中断+特定帧尾
2、接收数据中断+空闲中断
3、DMA接收+空闲中断
我最推荐第三种,尤其是数据量比较大且频繁的时候

串口配置
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
my_it.c

#include "my_it.h"
#include "mymain.h"
#include "main.h"
#include "gpio.h"
#include "tim.h"
#include "usart.h"
#include "uart_lcd.h"void MY_UART_IDLECallback(UART_HandleTypeDef *huart)//自定义的串口超时中断回调函数
{HAL_UART_DMAStop(&huart3);															//暂停DMAunsigned char data_length  = BUFFER_SIZE - __HAL_DMA_GET_COUNTER(&hdma_usart3_rx);	//计算此帧数据长度if(data_length == RBUFF_UNIT){unsigned char recv_data[10] = {0};memcpy(recv_data,receive_buff,RBUFF_UNIT);RxDataBufCheck(recv_data,RBUFF_UNIT);}//HAL_UART_Transmit_DMA(&huart3,receive_buff,data_length);							//回环测试,接收到什么返回什么HAL_UART_Receive_DMA(&huart3, (unsigned char*)receive_buff, BUFFER_SIZE);			//继续开启接收data_length = 0;
}void MY_UART_IRQHandler(UART_HandleTypeDef *huart)//此函数调用放在void USART3_IRQHandler(void)内执行
{if(USART3 == huart->Instance){if(RESET != __HAL_UART_GET_FLAG(&huart3, UART_FLAG_IDLE))	//判断是否是空闲中断{__HAL_UART_CLEAR_IDLEFLAG(&huart3);						//清除空闲中断MY_UART_IDLECallback(huart);							//空闲中断处理函数}}
}

my_it.h

#ifndef __MY_IT_H
#define __MY_IT_H
#include "log.h"
#include "usart.h"extern DMA_HandleTypeDef hdma_usart3_rx;void MY_UART_IRQHandler(UART_HandleTypeDef *huart);
void MY_UART_IDLECallback(UART_HandleTypeDef *huart);#endif

uart_lcd.c

#include "uart_lcd.h"
#include "sensor.h"
#include "dev_control.h"
#include <stdint.h>unsigned char  UART_RxDataBuf[R_NUM][RBUFF_UNIT];           //接收缓冲区
unsigned char *UART_RxDataInPtr;
unsigned char *UART_RxDataOutPtr;
unsigned char *UART_RxDataEndPtr;unsigned char  UART_TxDataBuf[T_NUM][TBUFF_UNIT];           //发送缓冲区
unsigned char *UART_TxDataInPtr;
unsigned char *UART_TxDataOutPtr;
unsigned char *UART_TxDataEndPtr;unsigned char receive_buff[BUFFER_SIZE];					//串口接收临时缓存//发送数据实例
#include "uart_lcd.h"
#include "sensor.h"
#include "dev_control.h"
#include <stdint.h>unsigned char  UART_RxDataBuf[R_NUM][RBUFF_UNIT];           //接收缓冲区
unsigned char *UART_RxDataInPtr;
unsigned char *UART_RxDataOutPtr;
unsigned char *UART_RxDataEndPtr;unsigned char  UART_TxDataBuf[T_NUM][TBUFF_UNIT];           //发送缓冲区
unsigned char *UART_TxDataInPtr;
unsigned char *UART_TxDataOutPtr;
unsigned char *UART_TxDataEndPtr;unsigned char receive_buff[BUFFER_SIZE];					//串口接收临时缓存//发送数据实例
unsigned char lcd_send_data[] = {0xFF,0x55,0x00,0x04,0x00,0x00,0x00,0x00,0xC1,0xBB};//大小端转化
unsigned short swapEndian16(unsigned short value) 
{return ((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8);
}unsigned int swapEndian32(unsigned int value) 
{return ((value & 0xFF000000) >> 24) |((value & 0x00FF0000) >> 8) |((value & 0x0000FF00) << 8) |((value & 0x000000FF) << 24);
}/* Table of CRC values for high order byte */
const uint8_t crctablehi[] = {0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81,0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,0x40
};
/* Table of CRC values for low order byte */
const uint8_t crctablelo[] = {0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7,0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE,0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2,0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB,0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91,0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88,0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,0x40
};unsigned short crc16Modbus(unsigned char *ptr, unsigned short len)
{unsigned char crchi = 0xff;unsigned char crclo = 0xff;unsigned short index;while(len--){index = crclo ^ *ptr++;crclo = crchi ^ crctablehi[index];crchi = crctablelo[index];}return (crchi | crclo << 8);//(crchi << 8 | crclo)高低字节互换//return (crchi << 8 | crclo);
}void uartLcdInit(void)
{UART_RxDataInPtr = UART_RxDataBuf[0];UART_RxDataOutPtr = UART_RxDataInPtr;UART_RxDataEndPtr = UART_RxDataBuf[R_NUM-1];UART_TxDataInPtr = UART_TxDataBuf[0];UART_TxDataOutPtr = UART_TxDataInPtr;UART_TxDataEndPtr = UART_TxDataBuf[T_NUM-1];__HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);//使能空闲中断HAL_UART_Receive_DMA(&huart3, (unsigned char*)receive_buff, BUFFER_SIZE);//开始DMA接收串口数据
}void uartLcdTask(void)//50ms调用一次,来定时处理缓存数据
{if(UART_RxDataOutPtr != UART_RxDataInPtr)//if成立说明缓冲区有数据了{//解析处理数据unsigned char recv_data[RBUFF_UNIT] = {0};memcpy(recv_data,UART_RxDataOutPtr,RBUFF_UNIT);RxDataBufAnalyze(recv_data);UART_RxDataOutPtr += RBUFF_UNIT;             //指针下移if(UART_RxDataOutPtr == UART_RxDataEndPtr)   //指针移动到缓冲区的尾部{UART_RxDataOutPtr = UART_RxDataBuf[0];   //指针归为到缓冲区开头}}if(UART_TxDataOutPtr != UART_TxDataInPtr)//if成立说明了发送缓冲区有数据了{UARTLCD_debug("TxData:%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\r\n",UART_TxDataOutPtr[0],UART_TxDataOutPtr[1],UART_TxDataOutPtr[2],UART_TxDataOutPtr[3],UART_TxDataOutPtr[4],UART_TxDataOutPtr[5],UART_TxDataOutPtr[6],UART_TxDataOutPtr[7],UART_TxDataOutPtr[8],UART_TxDataOutPtr[9]);HAL_UART_Transmit_DMA(&huart3,UART_TxDataOutPtr,TBUFF_UNIT);	//发送数据UART_TxDataOutPtr += TBUFF_UNIT;                      			//指针下移if(UART_TxDataOutPtr == UART_TxDataEndPtr)              		//指针移动到了缓冲区的尾巴{UART_TxDataOutPtr = UART_TxDataBuf[0];            			//指针归为到缓冲区开头}}
}void uartLcdMainUpdate(unsigned int num)	//在需要与串口屏发送数据的地方调用
{TxDataBufSend(UARTLCD_COMMAND_INIT_CHECK,num);
}void TxDataBufAdd(unsigned char *data)
{memcpy(UART_TxDataInPtr,data,TBUFF_UNIT);      					//拷贝数据到发送缓冲区UART_TxDataInPtr += TBUFF_UNIT;                 				//指针下移if(UART_TxDataInPtr == UART_TxDataOutPtr){UARTLCD_error("UART_TxDataBuf exceed !!!\r\n");				//缓存满了报错提示}if(UART_TxDataInPtr == UART_TxDataEndPtr)      					//指针移动到缓冲区的尾部{UART_TxDataInPtr = UART_TxDataBuf[0];    					//指针归为到缓冲区开头}
}void RxDataBufAdd(unsigned char *data)
{memcpy(UART_RxDataInPtr,data,RBUFF_UNIT);  						//拷贝数据到接收缓冲区UART_RxDataInPtr += RBUFF_UNIT;                     			//指针下移if(UART_RxDataInPtr == UART_RxDataOutPtr)           			//缓存满了报错提示{UARTLCD_error("UART_RxDataBuf exceed !!!\r\n");}if(UART_RxDataInPtr == UART_RxDataEndPtr)           			//指针移动到缓冲区的尾部{UART_RxDataInPtr = UART_RxDataBuf[0];           			//指针归为到缓冲区开头}
//	for(int i = 0;i<10;i++)
//	{
//		for(int j = 0;j<10;j++)
//		{
//			Debug_printf("%x,",UART_RxDataBuf[i][j]);
//		}
//		Debug_printf("\r\n");
//	}
//	Debug_printf("\r\n");
}void TxDataBufPack(unsigned char command,unsigned int num)	//发送串口数据封包
{uartLcdDataFrame_t * send_data = (uartLcdDataFrame_t *)lcd_send_data;send_data->bodyData.commandData = command;send_data->bodyData.controlData = swapEndian32(num);unsigned char bodyData[RBUFF_UNIT-2] = {0};memcpy(bodyData,&send_data->bodyData,RBUFF_UNIT-2);unsigned short send_crc = crc16Modbus(bodyData,RBUFF_UNIT-2);send_data->crcData = send_crc;TxDataBufAdd((unsigned char *)send_data);
}void TxDataBufSend(unsigned char command,unsigned int num)	//直接发送数据,不经过缓存
{uartLcdDataFrame_t * send_data = (uartLcdDataFrame_t *)lcd_send_data;send_data->bodyData.commandData = command;send_data->bodyData.controlData = swapEndian32(num);unsigned char bodyData[RBUFF_UNIT-2] = {0};memcpy(bodyData,&send_data->bodyData,RBUFF_UNIT-2);unsigned short send_crc = crc16Modbus(bodyData,RBUFF_UNIT-2);send_data->crcData = send_crc;unsigned char send_data_[TBUFF_UNIT] = {0};memcpy(send_data_,send_data,TBUFF_UNIT);UARTLCD_debug("TxDataBufSend:%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\r\n",send_data_[0],send_data_[1],send_data_[2],send_data_[3],send_data_[4],send_data_[5],send_data_[6],send_data_[7],send_data_[8],send_data_[9]);HAL_UART_Transmit_DMA(&huart3,(unsigned char *)lcd_send_data,TBUFF_UNIT);HAL_Delay(2);
}void RxDataBufCheck(unsigned char *data,unsigned char length)	//校验接收到的串口数据是不是一帧数据
{if(length != RBUFF_UNIT) return;uartLcdDataFrame_t * recv_data = (uartLcdDataFrame_t *)data;if(recv_data->bodyData.headData == 0x55FF)//校验头{unsigned char bodyData[RBUFF_UNIT-2] = {0};memcpy(bodyData,&recv_data->bodyData,RBUFF_UNIT-2);unsigned short recv_crc = crc16Modbus(bodyData,RBUFF_UNIT-2);if(recv_crc == recv_data->crcData)//校验CRC{
//			Debug_printf("RxDataBufCheck recv data:%x,%x,%x,%x,%x\r\n",
//			recv_data->bodyData.headData,recv_data->bodyData.commandData,recv_data->bodyData.lengthData,
//			recv_data->bodyData.controlData,recv_data->crcData);RxDataBufAdd(data);//加入环形缓冲区}}
}void RxDataBufAnalyze(unsigned char *data)	//处理串口指令
{UARTLCD_debug("RxDataBufAnalyze:%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\r\n",data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9]);uartLcdDataFrame_t * recv_data = (uartLcdDataFrame_t *)data;switch(recv_data->bodyData.commandData){case UARTLCD_COMMAND_INIT_CHECK:break;case UARTLCD_COMMAND_FLOW_LEVEL:break;case UARTLCD_COMMAND_SMOKE_CLEAN:break;case UARTLCD_COMMAND_AIR_CONSUME:break;case UARTLCD_COMMAND_PRESSURE_NOW:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_PRESSURE_TARGET:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_PRESSURE_REDUCE:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_PRESSURE_ADD:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_FLOW_NOW:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_FLOW_TARGET:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_FLOW_REDUCE:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_FLOW_ADD:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_PRESSURE_MODE:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_HEAT_STATE:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_AIR_START:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_AIR_INPUT_STATE:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_BUZZER_LEVEL:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_LANGUAGE:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_MESSAGE_WARNING:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_LIGHT_WARNING:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_USB_CHANGE:devBuzzerSetNum(1);break;case UARTLCD_COMMAND_VERSION_MESSGAE:devBuzzerSetNum(1);break;			default:break;}
}	

uart_lcd.h

#ifndef __UART_LCD_H
#define __UART_LCD_H
#include "main.h"
#include "log.h"
#include "usart.h"
#include "eeprom.h"
#include <string.h>#define UARTLCD_TASK_PERIOD  2 //#define UARTLCD_LOG_EN 0
#if UARTLCD_LOG_EN#define UARTLCD_printf(format, ...) 		printf(RTT_CTRL_TEXT_WHITE format , ##__VA_ARGS__)//"\r\n"#define UARTLCD_info(format, ...)   		printf(RTT_CTRL_TEXT_GREEN"[uartlcd]info:" format , ##__VA_ARGS__)#define UARTLCD_debug(format, ...)  		printf(RTT_CTRL_TEXT_WHITE"[uartlcd]debug:" format , ##__VA_ARGS__)#define UARTLCD_warning(format, ...)  	printf(RTT_CTRL_TEXT_YELLOW"[uartlcd]warning:" format , ##__VA_ARGS__)#define UARTLCD_error(format, ...)  		printf(RTT_CTRL_TEXT_RED"[uartlcd]error:" format ,##__VA_ARGS__)
#else#define UARTLCD_printf(format, ...)#define UARTLCD_info(format, ...)#define UARTLCD_debug(format, ...)#define UARTLCD_warning(format, ...)#define UARTLCD_error(format, ...)
#endif#define  R_NUM               20     //缓冲区的个数(可以缓存几帧数据)
#define  RBUFF_UNIT          10   	//缓冲区一帧数据的长度#define  T_NUM               20     //缓冲区的个数(可以缓存几帧数据)
#define  TBUFF_UNIT          10   	//缓冲区一帧数据的长度extern unsigned char  UART_RxDataBuf[R_NUM][RBUFF_UNIT];           //接收缓存区
extern unsigned char *UART_RxDataInPtr;                            //接收缓存区存放数据的位置
extern unsigned char *UART_RxDataOutPtr;                           //接收缓存区读取数据的位置
extern unsigned char *UART_RxDataEndPtr;                           //接收缓存区结束的位置extern unsigned char  UART_TxDataBuf[T_NUM][TBUFF_UNIT];           //发送缓存区
extern unsigned char *UART_TxDataInPtr;                            //发送缓存区存放数据的位置
extern unsigned char *UART_TxDataOutPtr;                           //发送缓存区读取数据的位置
extern unsigned char *UART_TxDataEndPtr;                           //发送缓存区结束的位置#define BUFFER_SIZE  100											//串口接收数据的临时缓存区大小
extern unsigned char receive_buff[BUFFER_SIZE];						//串口接收数据的临时缓存区typedef struct
{unsigned short headData;		//数据头unsigned char commandData;		//数据指令unsigned char lengthData;		//数据内容长度unsigned int controlData;		//数据内容
} uartLcdDataBody_t;typedef struct
{uartLcdDataBody_t bodyData;		//消息体unsigned short crcData;			//数据校验
} uartLcdDataFrame_t;enum{UARTLCD_COMMAND_INIT_CHECK,				UARTLCD_COMMAND_FLOW_LEVEL,		UARTLCD_COMMAND_SMOKE_CLEAN,	UARTLCD_COMMAND_AIR_CONSUME,	UARTLCD_COMMAND_PRESSURE_NOW,	UARTLCD_COMMAND_PRESSURE_TARGET,UARTLCD_COMMAND_PRESSURE_REDUCE,UARTLCD_COMMAND_PRESSURE_ADD,	UARTLCD_COMMAND_FLOW_NOW,		UARTLCD_COMMAND_FLOW_TARGET,	UARTLCD_COMMAND_FLOW_REDUCE,	UARTLCD_COMMAND_FLOW_ADD,		UARTLCD_COMMAND_PRESSURE_MODE,	UARTLCD_COMMAND_HEAT_STATE,		UARTLCD_COMMAND_AIR_START,		UARTLCD_COMMAND_AIR_INPUT_STATE,UARTLCD_COMMAND_BUZZER_LEVEL,	UARTLCD_COMMAND_LANGUAGE,		UARTLCD_COMMAND_MESSAGE_WARNING,UARTLCD_COMMAND_LIGHT_WARNING,	UARTLCD_COMMAND_USB_CHANGE,		UARTLCD_COMMAND_VERSION_MESSGAE	
};void uartLcdInit(void);
void uartLcdEndInit(void);
void uartLcdTask(void);unsigned short swapEndian16(unsigned short value);
unsigned int swapEndian32(unsigned int value);
unsigned short crc16Modbus(unsigned char *ptr, unsigned short len);void uartLcdMainUpdate(unsigned int num);					void TxDataBufAdd(unsigned char *data);							//向发送缓冲区加入一条待发送的数据
void RxDataBufAdd(unsigned char *data);							//向接收缓冲区加入一条待处理的数据
void RxDataBufCheck(unsigned char *data,unsigned char length);	//检验接收到串口数据是不是一帧合格的数据
void RxDataBufAnalyze(unsigned char *data);						//处理串口指令
void TxDataBufPack(unsigned char command,unsigned int num);		//发送串口数据封包
void TxDataBufSend(unsigned char command,unsigned int num);		//直接发送串口数据,不经过缓存#endif

这篇关于STM32CUBEMX_DMA串口空闲中断接收+接收发送缓冲区的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/203994

相关文章

Python实现自动化接收与处理手机验证码

《Python实现自动化接收与处理手机验证码》在移动互联网时代,短信验证码已成为身份验证、账号注册等环节的重要安全手段,本文将介绍如何利用Python实现验证码的自动接收,识别与转发,需要的可以参考下... 目录引言一、准备工作1.1 硬件与软件需求1.2 环境配置二、核心功能实现2.1 短信监听与获取2.

如何使用C#串口通讯实现数据的发送和接收

《如何使用C#串口通讯实现数据的发送和接收》本文详细介绍了如何使用C#实现基于串口通讯的数据发送和接收,通过SerialPort类,我们可以轻松实现串口通讯,并结合事件机制实现数据的传递和处理,感兴趣... 目录1. 概述2. 关键技术点2.1 SerialPort类2.2 异步接收数据2.3 数据解析2.

SpringBoot接收JSON类型的参数方式

《SpringBoot接收JSON类型的参数方式》:本文主要介绍SpringBoot接收JSON类型的参数方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、jsON二、代码准备三、Apifox操作总结一、JSON在学习前端技术时,我们有讲到过JSON,而在

Java中Springboot集成Kafka实现消息发送和接收功能

《Java中Springboot集成Kafka实现消息发送和接收功能》Kafka是一个高吞吐量的分布式发布-订阅消息系统,主要用于处理大规模数据流,它由生产者、消费者、主题、分区和代理等组件构成,Ka... 目录一、Kafka 简介二、Kafka 功能三、POM依赖四、配置文件五、生产者六、消费者一、Kaf

详解Spring Boot接收参数的19种方式

《详解SpringBoot接收参数的19种方式》SpringBoot提供了多种注解来接收不同类型的参数,本文给大家介绍SpringBoot接收参数的19种方式,感兴趣的朋友跟随小编一起看看吧... 目录SpringBoot接受参数相关@PathVariable注解@RequestHeader注解@Reque

Java如何接收并解析HL7协议数据

《Java如何接收并解析HL7协议数据》文章主要介绍了HL7协议及其在医疗行业中的应用,详细描述了如何配置环境、接收和解析数据,以及与前端进行交互的实现方法,文章还分享了使用7Edit工具进行调试的经... 目录一、前言二、正文1、环境配置2、数据接收:HL7Monitor3、数据解析:HL7Busines

SpringBoot中Get请求和POST请求接收参数示例详解

《SpringBoot中Get请求和POST请求接收参数示例详解》文章详细介绍了SpringBoot中Get请求和POST请求的参数接收方式,包括方法形参接收参数、实体类接收参数、HttpServle... 目录1、Get请求1.1 方法形参接收参数 这种方式一般适用参数比较少的情况,并且前后端参数名称必须

第10章 中断和动态时钟显示

第10章 中断和动态时钟显示 从本章开始,按照书籍的划分,第10章开始就进入保护模式(Protected Mode)部分了,感觉从这里开始难度突然就增加了。 书中介绍了为什么有中断(Interrupt)的设计,中断的几种方式:外部硬件中断、内部中断和软中断。通过中断做了一个会走的时钟和屏幕上输入字符的程序。 我自己理解中断的一些作用: 为了更好的利用处理器的性能。协同快速和慢速设备一起工作

STM32 ADC+DMA导致写FLASH失败

最近用STM32G070系列的ADC+DMA采样时,遇到了一些小坑记录一下; 一、ADC+DMA采样时进入死循环; 解决方法:ADC-dma死循环问题_stm32 adc dma死机-CSDN博客 将ADC的DMA中断调整为最高,且增大ADCHAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, ADC_Buffer_Size); 的ADC_Bu

Android中如何实现adb向应用发送特定指令并接收返回

1 ADB发送命令给应用 1.1 发送自定义广播给系统或应用 adb shell am broadcast 是 Android Debug Bridge (ADB) 中用于向 Android 系统发送广播的命令。通过这个命令,开发者可以发送自定义广播给系统或应用,触发应用中的广播接收器(BroadcastReceiver)。广播机制是 Android 的一种组件通信方式,应用可以监听广播来执行