最近在做基于TMS320F28335的运动控制。其中用到了28335的一些外设模块:SCI、ePWM、eQEP/AD等。为了以后能够有个回顾的地方,将学习过程中一些流程记录下来。
一、SCI串口通信相关配置流程与内容(中断方式)
Step1:初始化GPIO
InitSciGpio();
//只需设置SCIC和SCIB
Step2:初始化PIE中断向量表,(使用中断方式接收上位机数据)
EALLOW;
//寄存器EALLOW保护
PieVectTable.
SCIRXINTC=&scicRxFifoIsr;
//初始化PIE中断向量表
// PieVectTable.SCITXINTC=&scicTxFifoIsr;
EDIS;
//禁止写如EALLOW保护的寄存器
Step3:初始化SCI
SciSetup();
void SciSetup()
{
//SCIA设置
// Note: Clocks were turned on to the SCIC 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;
#if (CPU_FRQ_150MHZ)
ScicRegs.
SCIHBAUD =0x0001;
// 9600baud @LSPCLK = 37.5MHz.
ScicRegs.
SCILBAUD =0x00E7;
#endif
#if (CPU_FRQ_100MHZ)
ScicRegs.SCIHBAUD =0x0001;
//9600 baud @LSPCLK = 20MHz.
ScicRegs.SCILBAUD =0x0044;
#endif
//中断寄存器配置
ScicRegs.
SCIFFTX.
all=0x8000;
ScicRegs.
SCIFFRX.
all=0x0028;
ScicRegs.
SCIFFCT.
all=0x0;
ScicRegs.
SCICTL1.
all =0x0023;
// Relinquish SCI from Reset
ScicRegs.
SCIFFTX.
bit.
TXFIFOXRESET=1;
ScicRegs.
SCIFFRX.
bit.
RXFIFORESET=1;
}
//SCIC接收中断服务程序
interrupt
void scicRxFifoIsr(
void)
{
PieCtrlRegs.
PIEACK.
all=PIEACK_GROUP8;
//第八组中断响应
ReceivedChar = ScicRegs.
SCIRXBUF.
all;
ScicRegs.
SCIFFRX.
bit.
RXFIFORESET=0;
//复位FIFO
ScicRegs.
SCIFFRX.
bit.
RXFIFORESET=1;
// 使能FIFO
ScicRegs.
SCIFFRX.
bit.
RXFFOVRCLR=1;
//清除溢出标志
ScicRegs.
SCIFFRX.
bit.
RXFFINTCLR=1;
//清除中断标志
}
Step4:使能所需的中断
//使能所需的中断
PieCtrlRegs.
PIECTRL.
bit.
ENPIE=1;
//使能PIE模块
//SCI-C
PieCtrlRegs.
PIEIER8.
bit.
INTx5=1;
//PIE Group8,SCIRXINTC.
// PieCtrlRegs.PIEIER8.bit.INTx6=1;//PIEGroup8,SCITXINTC
IER|= M_INT8;
// 使能CPU的第八组中断--SCIC中断