我从dsPIC6010得UART口向CH375发送命令,结果从示波器看,有数据发出,命令应该是发出去了;这时候用示波器检查接受端,发现MCU并没有收到375得回答数据,可能是什么问题呢?配置是三线制,SIN,SOUT,GRD。
附上收发相关代码 unsigned char ExecCommand( unsigned char cmd, unsigned char len )//发送命令并处理返回
{ 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读扇区数据 i = 64; do { *buffer = mRecvByte( ); buffer ++; } while ( -- i ); } else if ( status == USB_INT_DISK_WRITE ) { //块写,375写扇区数据 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 )//发送字节 { IFS0bits.U1TXIF=0; //清除发送标志 U1STAbits.UTXEN=1; //发使能 U1TXREG = c; while ( IFS0bits.U1TXIF == 1 );
} unsigned char mRecvByte(void)//接受字节 { unsigned char c; while( IFS0bits.U1RXIF == 0); //等待接受标志被置位 c = U1RXREG; IFS0bits.U1RXIF = 0; return( c ); }