現(xiàn)用ch376芯片接收cp2102-(usb轉232芯片)發(fā)來的數(shù)據,有時候會出現(xiàn)接收誤碼,接收的長度是正確的,但是接收數(shù)據出現(xiàn)誤碼情況 我用串口調試打印情況如下
receive ok! count=6 data: 55 66 77 88 99 00 receive ok! count=6 data: 55 66 77 88 99 00 receive ok! count=6 data: 55 66 77 88 99 00 receive ok! count=6 data: 55 66 7f 7f 7f 7f receive ok! count=6 data: 55 66 77 88 99 00 receive ok! count=6 data: 55 66 7f 7f 7f 7f receive ok! count=6 data: 55 66 77 88 99 00 receive ok! count=6 data: 55 66 77 88 99 7f
正確的接收數(shù)據應該是55 66 77 88 99 00 但是ch376有時會接收到7f 這個數(shù)據,出現(xiàn)誤碼,麻煩幫忙分析下
unsigned char rd_usb_data( unsigned char *buf ) { /* 從CH37X讀出數(shù)據塊 */ unsigned char i, len; xWriteCH376Cmd(CMD_RD_USB_DATA0); len=xReadCH376Data(); /* 后續(xù)數(shù)據長度 */ for ( i=0; i!=len; i++ ) *buf++=xReadCH376Data(); return( len ); }
u8 xReadCH376Data( void ) /* 從CH376讀數(shù)據 */ { mDelayuS(1); /* 確保讀寫周期大于0.6uS */ return( CH376_ReadWrite( 0xff) ); }
延時函數(shù)什么的都應該是準的,程序里面實測過的。 表示有點想不通會出現(xiàn)ch376接收誤碼,出現(xiàn)的幾率還蠻大的,但是接收的長度都是正確的,表示無法理解