我從dsPIC6010得UART口向CH375發(fā)送命令,結(jié)果從示波器看,有數(shù)據(jù)發(fā)出,命令應(yīng)該是發(fā)出去了;這時(shí)候用示波器檢查接受端,發(fā)現(xiàn)MCU并沒(méi)有收到375得回答數(shù)據(jù),可能是什么問(wèn)題呢?配置是三線制,SIN,SOUT,GRD。
附上收發(fā)相關(guān)代碼 unsigned char ExecCommand( unsigned char cmd, unsigned char len )//發(fā)送命令并處理返回
{ unsigned char i, j, status;
IFS0bits.U1RXIF = 0; CH375HM_STA = 1; mSendByte( cmd ); mSendByte( len ); if ( len ) { for ( i = 0; i != len; i ++ ) mSendByte( mCmdParam.Other.mBuffer[ i ] ); } while ( 1 ) { status = mRecvByte(); if ( status == ERR_SUCCESS ) { i = mRecvByte(); if ( i ) { j = 0; do { mCmdParam.Other.mBuffer[ j ] = mRecvByte( ); j ++; } while ( -- i ); } break; } else if ( status == USB_INT_DISK_READ ) { //塊讀,375讀扇區(qū)數(shù)據(jù) i = 64; do { *buffer = mRecvByte( ); buffer ++; } while ( -- i ); } else if ( status == USB_INT_DISK_WRITE ) { //塊寫,375寫扇區(qū)數(shù)據(jù) i = 64; do { mSendByte( *buffer ); buffer ++; } while ( -- i ); } else if ( status == USB_INT_DISK_RETRY ) { i = mRecvByte( ); status = mRecvByte( ); buffer -= ( (unsigned short)status << 8 )+i; } else { break; } } return status; }
void mSendByte( unsigned char c )//發(fā)送字節(jié) { IFS0bits.U1TXIF=0; //清除發(fā)送標(biāo)志 U1STAbits.UTXEN=1; //發(fā)使能 U1TXREG = c; while ( IFS0bits.U1TXIF == 1 );
} unsigned char mRecvByte(void)//接受字節(jié) { unsigned char c; while( IFS0bits.U1RXIF == 0); //等待接受標(biāo)志被置位 c = U1RXREG; IFS0bits.U1RXIF = 0; return( c ); }