485
通信中,我的程序是主机,我要给从机发送:地址+数据。但是数据能发送出去,但是地址却发不了,帮我看看程序哪有问题。。。。。
void scib_fifo_init()
{
ScibRegs.SCICCR.all =0x000F; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScibRegs.SCICTL1.all =0x000A; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
//ScibRegs.SCICTL1.all =0x0003;
ScibRegs.SCICTL2.bit.TXINTENA =0;
ScibRegs.SCICTL2.bit.RXBKINTENA =0;
ScibRegs.SCIHBAUD =0x0000;
ScibRegs.SCILBAUD =0x006C; //28.8Kbps
ScibRegs.SCICCR.bit.LOOPBKENA =0; // Enable loop back
ScibRegs.SCIFFTX.all=0xC021;
ScibRegs.SCIFFRX.all=0x4021;
ScibRegs.SCIFFCT.all=0x00;
ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;
ScibRegs.SCIFFRX.bit.RXFIFORESET=1;
}
//======================================
//RS485发送函数
//======================================
void scib_xmit(int TargetAddr,int DataNum,int *TransData)
{
Uint16 i;
TX_EN;
for (i=0;i<130;i++)
{
;
}
ScibRegs.SCICCR.bit.ADDRIDLE_MODE =1; // 选择地址为协议
ScibRegs.SCICTL1.bit.TXWAKE=1; //发送模式唤醒
ScibRegs.SCITXBUF=TargetAddr; //发送地址
while (ScibRegs.SCICTL2.bit.TXEMPTY!=1); //等待发送完毕, 清除发送中断标志
ScibRegs.SCICTL1.bit.TXWAKE=0; //关闭唤醒
ScibRegs.SCICCR.bit.ADDRIDLE_MODE =0; // 空闲地址为协议
for (i=0;i<DataNum;i++)
{
ScibRegs.SCITXBUF=*TransData; //发送数据
while (ScibRegs.SCICTL2.bit.TXEMPTY!=1); //等待发送完毕, 清除发送中断标志
TransData++;
}
RX_EN; // Load output latch
ScibRegs.SCICCR.bit.ADDRIDLE_MODE =1; // 选择地址为协议
for (i=0;i<130;i++)
{
;
}
}
一周热门 更多>