利用串口助手 SCIA口自收自发,串口助手发送12个字符,会触发一次接收中断,在中断服务函数中,将数据发回串口助手,自己改写的程序,亲测好用
图为实验结果截图
下为实验代码
/**************************************************************
* SCIA口自收自发,串口助手发送12个字符,会触发一次接收中断,在中断服务函数中,将数据发回串口助手
**************************************************************/
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "string.h"
// Prototype statements for functions found within this file.
interrupt void sciaTxFifoIsr(void);
interrupt void sciaRxFifoIsr(void);
void scia_fifo_init(void);
void error(void);
void scia_xmit(int a);
void scia_msg(char *msg);
char m[12];
char *msg;//定义指针
void main(void)
{
InitSysCtrl();
InitSciGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.SCIRXINTA = &sciaRxFifoIsr;
PieVectTable.SCITXINTA = &sciaTxFifoIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
scia_fifo_init(); // Init SCI-A
msg = "\n\nWelcom to use TMS320F28335's SCI !";
scia_msg(msg);//先发送数据判断串口是否工作正常
// Enable interrupts required for this example
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, int1
PieCtrlRegs.PIEIER9.bit.INTx2=1; // PIE Group 9, INT2
PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT3
PieCtrlRegs.PIEIER9.bit.INTx4=1; // PIE Group 9, INT4
IER = 0x100; // Enable CPU INT
EINT;
while(1)
{
}
}
void error(void)
{
asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}
interrupt void sciaTxFifoIsr(void)
{
Uint16 i;
for(i=0;i<12;i++)
{
SciaRegs.SCITXBUF=m;
}
// ScibRegs.SCIFFTX.bit.TXFFINTCLR=1;//清楚发送FIFO中断标志位。在此处如果清零会导致发送FIFO中断一直产生,因此要关闭才行
PieCtrlRegs.PIEACK.bit.ACK9=1;
}
interrupt void sciaRxFifoIsr(void)
{
Uint16 i;
for(i=0;i<12;i++)
{
m=SciaRegs.SCIRXBUF.all;
}
msg = "\n\nYou just sent the following characters : ";
scia_msg(msg);
scia_msg(m);
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;
// ScibRegs.SCIFFTX.bit.TXFFINTCLR=1;
PieCtrlRegs.PIEACK.bit.ACK9=1;
}
void scia_fifo_init()
{
//SCI通信控制寄存器
SciaRegs.SCICCR.all =0x0007; //SCI数据长度控制位111,8位数据
//空闲模式,禁止循环自检模式
//不允许奇偶校验
//一位停止位
//SCI控制寄存器1
SciaRegs.SCICTL1.all =0x0003; // SCI发送使能,SCI接收使能
// Disable RX ERR, SLEEP, TXWAKE
// ScibRegs.SCICTL2.bit.TXINTENA =1;
// ScibRegs.SCICTL2.bit.RXBKINTENA =1;
SciaRegs.SCIHBAUD =0x0001;
SciaRegs.SCILBAUD =0x00E7;//设置波特率为9600
//SCI发送FIFO寄存器SCIFFTX
SciaRegs.SCIFFTX.bit.SCIFFENA=1;//使能FIFO
SciaRegs.SCIFFTX.bit.SCIRST=1;//SCI复位标志位,1.SCI接收和发送FIFO功能继续工作
SciaRegs.SCIFFTX.bit.TXFFIENA=0;//不使能发送FIFO中断
SciaRegs.SCIFFTX.bit.TXFFIL=0x0C;//12级FIFO使能
SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;//发送FIFO中断清除标志位,1,清除TXFFINT位
SciaRegs.SCIFFTX.bit.TXFIFOXRESET=0;//SCI发送FIFO复位,0,复位发送FIFO指针
//SCI接收FIFO寄存器SCIFFRX
SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;//SCI接收FIFO溢出清除标志位,1,清除RXFFOVF
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;//接收FIFO中断清除标志位
SciaRegs.SCIFFRX.bit.RXFIFORESET=0;//SCI接收FIFO复位,0,复位接收FIFO指针
SciaRegs.SCIFFRX.bit.RXFFIENA=1;//接收FIFO中断使能位,
SciaRegs.SCIFFRX.bit.RXFFIL=0x0C;//12级FIFO使能
//SCI FIFO控制寄存器SCIFFCT
SciaRegs.SCIFFCT.all=0x00;
// SCI控制寄存器1
SciaRegs.SCICTL1.bit.SWRESET=1;//Relinquish SCI from Reset
SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;
SciaRegs.SCIFFRX.bit.RXFIFORESET=1;
}
void scia_xmit(int a)//单个字符发送代码
{
while (SciaRegs.SCICTL2.bit.TXRDY == 0) {}
SciaRegs.SCITXBUF=a;
}
void scia_msg(char * msg)//发送字符串代码
{
Uint16 len;
Uint16 i;
len=(strlen(msg)-1);
for(i=0;i<len;i++)
{
scia_xmit(msg);
}
// return 0;
}
//===========================================================================
// No more.
//===========================================================================
|