TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F28377D: 菜鸟请教:SCI通信发送4字节数据,第一次收发可以实现,再次收发时会乱码或者无法接收

Part Number:TMS320F28377D

上电时,发送AABBA0FF,判断发送正常。

点手动发送AABBA1FF,可以接收到一次,后面再次点手动发送,无法接收到。有时还会出现第一次点手动发送AABBA1FF,显示乱码(比如收到BB 00 53这种)。

以下为代码(刚接触DSP,有挺多不太了解的地方,望大佬指正,万分感谢)

==============================================================================

#include "F28x_Project.h" // Device Headerfile and Examples Include File

// Prototype statements for functions found within this file.
void scic_echoback_init(void);
void scic_fifo_init(void);
void scic_xmit(int a);
void scic_msg(Uint16 *msg,Uint16 len);

// Global counts used in this example
Uint16 LoopCount;
#define RX_EN GpioDataRegs.GPCCLEAR.bit.GPIO68 = 1;
#define TX_EN GpioDataRegs.GPCSET.bit.GPIO68 = 1;
//Uint16 ReceivedChar;
Uint16 anwser[]={0x00AA,0x00BB,0x00A0,0x00FF};
int len;
Uint16 res[];
Uint16 *msg;

void main(void)
{

InitSysCtrl();

InitGpio();

EALLOW;
GpioCtrlRegs.GPBGMUX2.bit.GPIO56 = 1;
GpioCtrlRegs.GPBGMUX2.bit.GPIO57 = 1;
GpioCtrlRegs.GPBMUX2.bit.GPIO56 = 2;
GpioCtrlRegs.GPBMUX2.bit.GPIO57 = 2;

EDIS;
GPIO_SetupPinMux(68, GPIO_MUX_CPU1, 0);
GPIO_SetupPinOptions(68, GPIO_OUTPUT, GPIO_PUSHPULL);

DINT;

InitPieCtrl();

// Disable CPU __interrupts and clear all CPU __interrupt flags:
IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

// Step 4. User specific code:

LoopCount = 0;

scic_fifo_init(); // Initialize the SCI FIFO
scic_echoback_init(); // Initialize SCI for echoback
TX_EN

msg=anwser;
scic_msg(msg,6);

for(;;)
{
int i;
RX_EN;
// Wait for inc character
// while(ScicRegs.SCIFFRX.bit.RXFFST ==0){}// wait for XRDY =1 for empty state
while(ScicRegs.SCIRXST.bit.RXRDY == 0){}
for(i=0;i<4;i++)
// Get character
{
res[i]= ScicRegs.SCIRXBUF.all & 0x00FF;
LoopCount++;
}

scic_msg(res,6);
LoopCount = 0;
}

}

void scic_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function

ScicRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScicRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
ScicRegs.SCICTL2.all =0x0003;
ScicRegs.SCICTL2.bit.TXINTENA =1;
ScicRegs.SCICTL2.bit.RXBKINTENA =1;

//
// SCIA at 9600 baud
// @LSPCLK = 50 MHz (200 MHz SYSCLK) HBAUD = 0x02 and LBAUD = 0x8B.
// @LSPCLK = 30 MHz (120 MHz SYSCLK) HBAUD = 0x01 and LBAUD = 0x86.
//
ScicRegs.SCIHBAUD.all =0x0002;
ScicRegs.SCILBAUD.all =0x008B;

ScicRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}

void scic_msg(Uint16 *msg,Uint16 len)
{
int i;
TX_EN;
for(i=0;i<len;i++)
{
while (ScicRegs.SCICTL2.bit.TXRDY == 0) {}
ScicRegs.SCITXBUF.all =msg[i]&0x00FF;
}
RX_EN;
}

// Initialize the SCI FIFO
void scic_fifo_init()
{
ScicRegs.SCIFFTX.all=0xE040;//SCI reset,FIFO 增强功能使能,再次使能发送FIFO,清除TXFFINT标志
ScicRegs.SCIFFRX.all=0x2040;//SCI reset,清除TXFFINT标志,中断深度0
ScicRegs.SCIFFCT.all=0x0;
}

gao feng:

还有两处不解:

1.scic_msg()函数里,len写4,在上电运行的时候,串口的接收区收到的是AABB,写6才收到AABBA0FF,这是为什么?不是循环一次,发送一个字节的数据吗?

2.单步运行看了一下,在第二次第三次…按手动发送按钮,串口接收区没有数据时,代码停在 while(ScicRegs.SCIRXST.bit.RXRDY == 0) {} 这一行,代码反映的问题是没有接收到新数据,可是我明明发送了,这是什么问题呢?

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F28377D: 菜鸟请教:SCI通信发送4字节数据,第一次收发可以实现,再次收发时会乱码或者无法接收
分享到: 更多 (0)