请版主和各位同行帮助解决一个485通讯的问题,急!!!
|
||||
---|---|---|---|---|
新會員
|
我现在用DSPIC30F6014作一个项目,在调试串口2时,遇到问题。请帮我看一下用串口2发送数据的测试程序。我现在用一个RS232转RS485的转换器进行调试,一端接PC机,一端接我的PCB板,调试中出现的问题是:发出去的数,接收的不对。我测试了RS232转RS485的转换器,收发没有问题。测试了我的PCB板上的RS485转换器DS75176B,没问题,我想请您看一下我的程序是否正确,哪位有已测试好的程序请给我发一份。谢谢!我的邮箱是:kscg1234@126.com
//*******************************************************************************// int main(void) { INT8U i; INIUART2(); commdelaynms(10); for(;;) //for(i=0;i<2;i++) { while(U2STAbits.UTXBF); U2TXREG=0x01; while(U2STAbits.TRMT==0); IFS1bits.U2TXIF = 0; U2STAbits.UTXBRK=1; commdelaynms(20); U2STAbits.UTXBRK=0; commdelaynms(10); } } //*******************************************************************************// void INIUART2(void) //串口初始化 { TRISCbits.TRISC14 =0; //RE TRISFbits.TRISF5 =0; //TXD1 TRISFbits.TRISF4 =1; //RXD1 //TRISFbits.TRISF2 =1; //RXD0 //TRISFbits.TRISF3 =0; //TXD0 U2BRG =103; U2MODE =0x0000; //IEC1bits.U2RXIE=1; IEC1bits.U2TXIE=1; IPC6bits.U2TXIP=7; IPC6bits.U2RXIP=5; U2STAbits.UTXISEL=0; U2MODE =0x8000; //使能UART IFS1bits.U2TXIF = 1; IFS1bits.U2RXIF = 1; PORTCbits.RC14 =1; //使SN75176B处于发送状态 U2STAbits.UTXEN = 1; //使能发送 } //***********************************************************************************// //*********************************************************// void __attribute__((__interrupt__)) _U2RXInterrupt(void) { IFS1bits.U2RXIF = 0; } //*********************************************************// void _ISR _U2TXInterrupt() { IFS1bits.U2TXIF=0; //Reset uart interrupt flag } //*********************************************************//
發表於: 2006/5/19 11:03
|
|||
|