Data send adapt CRC16 verification,The following is the function of CRC16,please refer
//-------------------------------------------------------------------------------------------
unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT)
{
unsigned short CRC_Temp;
unsigned char i,j;
CRC_Temp = 0xffff;
for (i=0;i<CRC_CNT; i++){
CRC_Temp ^= Buf;
for (j=0;j<8;j++) {
if (CRC_Temp & 0x01)
CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
else
CRC_Temp = CRC_Temp >> 1;
}
}
return(CRC_Temp);
}
//-------------------------------------------------------------------------------------------
The data from computer to MPU is like this:
Ch1_Addr_LL,Ch1_Addr_LH,
Ch1_Addr_HL,Ch1_Addr_HH,
Ch2_Addr_LL,Ch2_Addr_LH,
Ch2_Addr_HL,Ch2_Addr_HH,
Ch3_Addr_LL,Ch3_Addr_LH,
Ch3_Addr_HL,Ch3_Addr_HH,
Ch4_Addr_LL,Ch4_Addr_LH,
Ch4_Addr_HL,Ch4_Addr_HH,
CRC16_L,CRC16_H
//-------------------------------------------------------------------------------------------
The data from MPU to computer should be like this:
Ch1Data_L,Ch1Data_H,
Ch2Data_L,Ch2Data_H,
Ch3Data_L,Ch3Data_H,
Ch4Data_L,Ch4Data_H,
CRC16_L,CRC16_H
//-------------------------------------------------------------------------------------------
the following is MPU code,please refer.
//-------------------------------------------------------------------------------------------
#define RxCountMax 18
unsigned short RxBuf[RxCountMax];
unsigned short TxBuf[10];
unsigned short RxCnt;
unsigned short TxCnt;
unsigned short Rx50msCnt;
unsigned long pAddr1,pAddr2,pAddr3,pAddr4;
//Receive interrupt routine
void voRxIsr(void)
{
unsigned short i,CRC_RX,CRC_Tmp;
RxBuf[RxCnt] = Rx.data; //acquire data
RxCnt++;
ChxData[0].sw = *(unsigned short *)pAddr1;
ChxData[1].sw = *(unsigned short *)pAddr2;
ChxData[2].sw = *(unsigned short *)pAddr3;
ChxData[3].sw = *(unsigned short *)pAddr4;