PM2.5传感器Modbusrtu通讯协议.doc:..-、标准modbus协议说明1、串口设置波特率9600,无校验,数据位8,停止位1。力能通讯命令16进制:00030000000185DB(不清楚设备地址可用此找冋)2、接口说明请接入GND(地\电源负极),TX(模组串口发对应串口线收),RX(模组串口收对应串口线发)对应接口。调试不通请交换串口线再试。4、CRC16校验计算函数(请确认单片机人端编程还是小端)返回shortint参数data【】数组、Ion数组长度例子:datax[8]={01,03,00,00,00,01,00,00}16进制unsignedshortintx=CRC_16(datax,6);得到x=0x840a;sixxlx /吓、XT%ZJX IunsignedshortintCRC_16(unsignedchar*data,intlen)unsignedchar*buf;unsignedshortint*CRC;unsignedshortintcrch,crcl;shortinti;shortintj;charerr;buf=&data[len];CRC=(unsignedshortint*)buf;buf[0]=0xff;buf[l]=0xff;for(i=0;i<len;i++){buf[0]=buf[0]"data[i];for(j=0;j<8;j++)!err=buf[0]&l;*CRC=*CRC/2;if(err)*CRO*CRCfOxaOO1;}}crch=*CRC>>8;crcl=*CRC«8;*CRC=crch+crcl;return(*CRC);/******************函数CRC_16()*********小端返回shortint参数data【】数组、len数组长度例子:datax[8]={01,03,00,00,00,01,00,00}16进制unsignedshortintx=CRC_16(datax,
PM2.5传感器Modbusrtu通讯协议 来自淘豆网www.taodocs.com转载请标明出处.