與導航儀的usb口相連, 選擇CH375好還是CH374好?

我想用CH375,CH374和導航儀的USB口連接,把單片機采集的數(shù)據(jù)發(fā)給導航儀,目前用參考樣例的程序可以連接并發(fā)送數(shù)據(jù)了,但不是很流暢,有時收不到。有兩個問題需要大家?guī)蛶兔Γ? 1。作為host跟其他usb設備通訊,是否CH374更好? 2。USB_INT_DISK_WRITE,USB_INT_DISK_READ 是否只能用在讀U盤時,返回中斷狀態(tài)中才會出現(xiàn)?

1,如果對速度有要求的話,同時是高速單片機和CH374芯片連接的話,那么推薦使用CH374 2 你所說的2條命令是只能用于對U盤的讀寫時中斷狀態(tài)返回。 不知道你采集的速度是多快?導航儀是個什么USB設備?和計算機通信的速度是多快?這樣也好確定問題在什么地方?


1. 我用的是STC89C52單片機,速度不快,不知道CH374編程是否需要更多理解USB協(xié)議 我的現(xiàn)在是單片機用串口連接PC的串口,用CH375連接導航儀的USB otg(device)。用PC電腦模擬把數(shù)據(jù)傳給導航儀,采集數(shù)據(jù)方面還沒試。

2。如果這個狀態(tài)不能查詢,是否還能用其他的方法知道,當CH375置中斷位為零時,我如何知道我是可以寫數(shù)據(jù)還是可以讀數(shù)據(jù)。以下是我的部分程序:

void CH375_WR_CMD_PORT( unsigned char cmd ) { _nop_(); _nop_(); CH375_CMD_DAT = 1; /* ?üá? */ CH375_DATA_PORT = cmd; CH375_RD = 1; CH375_WR = 0; _nop_(); _nop_(); CH375_WR = 1; CH375_CMD_DAT = 0; CH375_DATA_PORT = 0xFF; }

void CH375_WR_DAT_PORT( unsigned char dat ) { _nop_(); CH375_CMD_DAT = 0; /* êy?Y */ CH375_DATA_PORT = dat; CH375_RD = 1; CH375_WR = 0; _nop_(); CH375_WR = 1; CH375_DATA_PORT = 0xFF; }

unsigned char CH375_RD_DAT_PORT(void) { unsigned char rev_data; CH375_DATA_PORT = 0xFF; CH375_CMD_DAT = 0; CH375_WR = 1; CH375_RD = 0; _nop_(); rev_data = CH375_DATA_PORT; CH375_RD = 1; return( rev_data ); }

unsigned char wait_interrupt(void) { CH375_INT_WIRE = 1; while( CH375_INT_WIRE ) { if( RI==1 ) /* ′??ú?óê?μ?êy?Y */ { CH375_WR_CMD_PORT( CMD_ABORT_NAK ); /* ·??úμ±?°2ù×÷ */ return( 0xEF ); } } CH375_WR_CMD_PORT( CMD_GET_STATUS ); return( CH375_RD_DAT_PORT() ); }

/* éè??CH37Xμ?1¤×÷?£ê? */ void set_usb_mode( unsigned char mode ) { unsigned char i; CH375_WR_CMD_PORT( CMD_SET_USB_MODE ); CH375_WR_DAT_PORT( mode ); endp6_mode=endp7_mode=0x80; for( i=100; i!=0; i-- ) { if( CH375_RD_DAT_PORT() == CMD_RET_SUCCESS ) return; } while(1) { flash_led(); } }

void toggle_recv(void) { CH375_WR_CMD_PORT( CMD_SET_ENDP6 ); CH375_WR_DAT_PORT( endp6_mode ); endp6_mode^=0x40; delay2us(); }

void toggle_send(void) { CH375_WR_CMD_PORT( CMD_SET_ENDP7 ); CH375_WR_DAT_PORT( endp7_mode ); endp7_mode^=0x40; delay2us(); }

unsigned char clr_stall6(void) { CH375_WR_CMD_PORT( CMD_CLR_STALL ); CH375_WR_DAT_PORT( 2 ); endp6_mode=0x80; return( wait_interrupt() ); }

unsigned char clr_stall7(void) { CH375_WR_CMD_PORT( CMD_CLR_STALL ); CH375_WR_DAT_PORT( endp_out_addr ); endp7_mode=0x80; return( wait_interrupt() ); }

unsigned char rd_usb_data( unsigned char *buf ) { unsigned char len, length; CH375_WR_CMD_PORT( CMD_RD_USB_DATA ); len=CH375_RD_DAT_PORT(); length=len; while( len-- ) { *buf = CH375_RD_DAT_PORT(); buf++; } return( length ); }

void wr_usb_data( unsigned char len, unsigned char *buf ) { CH375_WR_CMD_PORT( CMD_WR_USB_DATA7 ); CH375_WR_DAT_PORT( len ); while( len-- ) { CH375_WR_DAT_PORT( *buf ); buf++; } }

unsigned char issue_token( unsigned char endp_and_pid ) { unsigned char status; CH375_WR_CMD_PORT( CMD_ISSUE_TOKEN ); CH375_WR_DAT_PORT( endp_and_pid ); status = wait_interrupt(); return( status ); }

void host_send( unsigned char len, unsigned char *buf ) { unsigned char status; unsigned char length; led=1; while( len ) { if( len>endp_out_size ) length=endp_out_size; else length=len; wr_usb_data( length, buf ); toggle_send(); status = issue_token( ( endp_out_addr << 4 ) | DEF_USB_PID_OUT ); if( status==USB_INT_SUCCESS ) { len -= length; buf += length; } else if( status==0xEF ) { led=0; return; } else if( status != 0xEF ) { clr_stall7(); } } led=0; }

unsigned char host_recv( unsigned char *buf ) { unsigned char status; if( endp_in_addr ) { toggle_recv(); status = issue_token( ( endp_in_addr << 4 ) | DEF_USB_PID_IN ); // status = issue_token( ( 2 << 4 ) DEF_USB_PID_IN ); if( status==USB_INT_SUCCESS ) { status = rd_usb_data( buf ); return( status ); } else if( status==USB_INT_DISCONNECT ) { return( 0xFE ); } else { clr_stall6(); return( 0xFF ); } } return( 0xFF ); /* ·μ??2ù×÷꧰ü */ }

unsigned char get_descr( unsigned char type ) /* ′óéè±?????è??èê?·? */ { CH375_WR_CMD_PORT( CMD_GET_DESCR ); CH375_WR_DAT_PORT( type ); /* ?èê?·?ààDí, ???§3?1(éè±?)?ò??2(????) */ return( wait_interrupt() ); /* μè′yCH3752ù×÷íê3é */ }

unsigned char set_addr( unsigned char addr ) /* éè??éè±???μ?USBμ??· */ { unsigned char status; CH375_WR_CMD_PORT( CMD_SET_ADDRESS ); /* éè??USBéè±???μ?USBμ??· */ CH375_WR_DAT_PORT( addr ); /* μ??·, ′ó1μ?127????μ?è?òa?μ, 3£ó?2μ?20 */ status=wait_interrupt(); /* μè′yCH3752ù×÷íê3é */ if( status==USB_INT_SUCCESS ) /* 2ù×÷3é1| */ { CH375_WR_CMD_PORT( CMD_SET_USB_ADDR ); /* éè??USB?÷?ú??μ?USBμ??· */ CH375_WR_DAT_PORT( addr ); /* μ±??±êUSBéè±?μ?μ??·3é1|DT??oó,ó|??í?2?DT???÷?ú??μ?USBμ??· */ } return( status ); }

unsigned char set_config( unsigned char cfg ) /* éè??éè±???μ?USB???? */ { endp6_mode=endp7_mode=0x80; /* ?′??USBêy?Yí?2?±ê?? */ CH375_WR_CMD_PORT( CMD_SET_CONFIG ); /* éè??USBéè±???μ??????μ */ CH375_WR_DAT_PORT( cfg ); /* ′??μè?×?USBéè±?μ??????èê?·??D */ return( wait_interrupt() ); /* μè′yCH3752ù×÷íê3é */ }

void SendChars( unsigned char *buff ) { unsigned char buf; while(1) { buf = *buff; if( buf == 0x00 ) break; SBUF = buf; buff++; while( !TI ); TI=0; } }

void receive(void) { unsigned int count; unsigned char buf; RECV_LEN=0; cmd_buf = RECV_BUFFER; /* ?óê??o3??? */ while( 1 ) { RI=0; *cmd_buf = SBUF; cmd_buf++; RECV_LEN++; if( RECV_LEN == 64 ) { while( 1 ) { count=10000; while( RI==0 ) { count--; if( count==0 ) return; } RI=0; buf=SBUF; } } count=10000; while( RI==0 ) { count--; if( count==0 ) return; } } }

void main(void) { unsigned char i; unsigned char length; delay1s(); CH375_Init(); //initial CH375 host , test and set mode 6; ComInit(); //init Uart Port SendChars("USB Init OK\n");

led=0; while(1) { led=0; while (1) { if( wait_interrupt() == USB_INT_CONNECT ) { SendChars( "Device Connect\n" ); break; } } set_usb_mode( 7 ); delay50ms(); set_usb_mode( 6 ); while (1) { if( wait_interrupt() == USB_INT_CONNECT ) SendChars( "Device re-connect\n" ); break; } delay1s(); for( i=5;i!=0;i-- ) { if( init_USB_device() != USB_INT_SUCCESS ) { SendChars("device init failed\n"); flash_led(); //′í?ó } else { break; } } if( i==0 ) { flash_led(); continue; } while(1) { ret_buf = RECV_BUFFER; length = host_recv( ret_buf ); if( length == 0xEF ) { led=1; receive(); led=0; ret_buf = RECV_BUFFER; length = RECV_LEN; if( length!=0 ) host_send( length, ret_buf ); } else if( length == 0xFE ) { SendChars( "USB_Disconnect\n" ); break; } else if( length != 0xFF ) { ret_buf = RECV_BUFFER; while( length-- ) { SendChar( *ret_buf ); ret_buf++; } } } } }


1,首先你需要確認你通信不流暢是因為串口那邊的問題還是USB口這邊的問題,需要確認問題之后才好解決問題。 2,根據(jù)USB特性,作為USB主機端是是通信的發(fā)起者,所以你應該自己確認應該發(fā)還是應該收數(shù)據(jù),按照計算機的操作方式是這樣,在檢測到設備連接之后,是不斷的發(fā)送IN的令牌包,這個IN的令牌包的間隔為1MS左右。運用到你的實際設備上面應該這樣: 串口開中斷接收數(shù)據(jù),單片機不斷的通過CH375發(fā)送IN的令牌包來取數(shù)據(jù),當有取到數(shù)據(jù)就通過串口發(fā)送出去。如果沒有就繼續(xù)取數(shù)據(jù)。當串口來數(shù)據(jù)時,這個時候主機發(fā)送一包OUT令牌包出去,同時把數(shù)據(jù)發(fā)送出去。這樣應該就沒有問題了。


感謝hcn提醒,你真熱心啊,我再根據(jù)你的思路研究研究。 另外還有一個問題是我的CH375鏈接導航儀USB otg(device)時,這個usb otg老是不斷的連接,過幾秒后又斷開,又開始鏈接,如果發(fā)送或接受數(shù)據(jù)時,它就不會斷開或連接,根據(jù)設備描述符2的得到的信息,這個usb otg設備是自供電,最大需求電流0(即:配置描述符的bmAttributes=1100 0000,MaxPower=0)。 如果我把usb otg連到電腦上,在設備管理器里也是這樣鏈接又斷開,又連接。只有打開microsoft activesync后,usb otg就一直連著PC,在設備管理器里也不閃了,不知道CH375是否能設置一直讓它連接著?


建議你使用一款軟件叫“BUSHOUND”,你采用這個軟件看下在你打開microsoft activesync軟件之后,計算機給你的導航儀發(fā)送了什么命令,CH375按照導航儀的命令來發(fā),這樣的話就不會出現(xiàn)你說的問題。


還是網(wǎng)上高人多?。?/p>


只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频