DSP28335的SCI发送问题,SCI一直发送不了,怎么办?
下面是采用轮询方式,针对DSP28335的SCI模块,编写的发送接收串口程序。目的其实很简单就是PC经USB转485串口线连接DSP,然后给DSP发送一个或者多个字符,然...
下面是采用轮询方式,针对DSP28335的SCI模块,编写的发送接收串口程序。目的其实很简单就是PC经USB转485串口线连接DSP,然后给DSP发送一个或者多个字符,然后DSP原样返回发送给PC。但现在的问题是DSP程序接收正常,接收到的数据也是正确的,但DSP一直不能将数据发送回PC。调试时发现for(;;)循环中的变量 i 是不断增加的,并且SCITXBUF寄存器是有数据的,但数据却一直没有被移出。哪位大侠抽空指点一下,新手将不胜感激(好心人帮帮忙现在暂时没有财富了。。。)
以下是程序:
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
unsigned int Scib_VarRx[100];
unsigned int i;
unsigned int Send_Flag;
unsigned int RX_Flag;
unsigned int TX_Flag;
#define InitDIR() \
EALLOW; \
GpioCtrlRegs.GPBPUD.bit.GPIO49 = 0; \
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; \
GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1; \
EDIS;
#define RX_EN GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;;
#define TX_EN GpioDataRegs.GPBSET.bit.GPIO49 = 1;
void InitScib(void){
ScibRegs.SCICTL1.bit.SWRESET =0;
ScibRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScibRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
#if (CPU_FRQ_150MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
ScibRegs.SCILBAUD =0x00E7;
#endif
#if (CPU_FRQ_100MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 20MHz.
ScibRegs.SCILBAUD =0x0044;
#endif
ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
int ScibTx_Ready(void){
unsigned int i;
TX_Flag = ScibRegs.SCICTL2.bit.TXRDY;
if(ScibRegs.SCICTL2.bit.TXRDY == 1)
i = 1;
else
i = 0;
return(i);
}
int ScibRx_Ready(void){
unsigned int i;
RX_Flag = ScibRegs.SCIRXST.bit.RXRDY;
if(ScibRegs.SCIRXST.bit.RXRDY == 1)
i = 1;
else
i = 0;
return(i);
}
void main(void){
InitSysCtrl();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitScibGpio();
InitDIR();
InitScib();
for(i = 0; i < 100; i++)
Scib_VarRx[i] = 0;
i = 0;
Send_Flag = 0;
for(;;){
if(ScibRx_Ready() == 1){
Scib_VarRx[i] = ScibRegs.SCIRXBUF.all;
Send_Flag = 1;
}
if((ScibTx_Ready() == 1) && (Send_Flag == 1)){
TX_EN;
ScibRegs.SCITXBUF = Scib_VarRx[i];
RX_EN;
Send_Flag = 0;
i++;
if(i >= 100)
i = 0;
}
}
}
再附上RS485的接线图 展开
以下是程序:
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
unsigned int Scib_VarRx[100];
unsigned int i;
unsigned int Send_Flag;
unsigned int RX_Flag;
unsigned int TX_Flag;
#define InitDIR() \
EALLOW; \
GpioCtrlRegs.GPBPUD.bit.GPIO49 = 0; \
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; \
GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1; \
EDIS;
#define RX_EN GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;;
#define TX_EN GpioDataRegs.GPBSET.bit.GPIO49 = 1;
void InitScib(void){
ScibRegs.SCICTL1.bit.SWRESET =0;
ScibRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScibRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
#if (CPU_FRQ_150MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
ScibRegs.SCILBAUD =0x00E7;
#endif
#if (CPU_FRQ_100MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 20MHz.
ScibRegs.SCILBAUD =0x0044;
#endif
ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
int ScibTx_Ready(void){
unsigned int i;
TX_Flag = ScibRegs.SCICTL2.bit.TXRDY;
if(ScibRegs.SCICTL2.bit.TXRDY == 1)
i = 1;
else
i = 0;
return(i);
}
int ScibRx_Ready(void){
unsigned int i;
RX_Flag = ScibRegs.SCIRXST.bit.RXRDY;
if(ScibRegs.SCIRXST.bit.RXRDY == 1)
i = 1;
else
i = 0;
return(i);
}
void main(void){
InitSysCtrl();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitScibGpio();
InitDIR();
InitScib();
for(i = 0; i < 100; i++)
Scib_VarRx[i] = 0;
i = 0;
Send_Flag = 0;
for(;;){
if(ScibRx_Ready() == 1){
Scib_VarRx[i] = ScibRegs.SCIRXBUF.all;
Send_Flag = 1;
}
if((ScibTx_Ready() == 1) && (Send_Flag == 1)){
TX_EN;
ScibRegs.SCITXBUF = Scib_VarRx[i];
RX_EN;
Send_Flag = 0;
i++;
if(i >= 100)
i = 0;
}
}
}
再附上RS485的接线图 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |