(5) DSP28335--SCI
(2016-07-01 22:39:13)
分类:
DSP学习
对于28335---SCI编程例程
1 SCI模块初始化(主频100M)
在main函数的初始化外设中设置SCI模块,这里使用SCIA仅用于接收;
SCIC采用中断接收,定时发送;
//----------------------------------------------------------
使能SCI外设时钟
{
SysCtrlRegs.PCLKCR0.bit.SCIAENCLK = 1; // SCI-A
SysCtrlRegs.PCLKCR0.bit.SCICENCLK = 1; // SCI-A
}
//-----------------------------------------------------------
//设置SCI模块
void InitSCI()
{
////SCIC
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.bit.TXINTENA =1;//enable TXRDY isr
ScicRegs.SCICTL2.bit.RXBKINTENA =1;//enable RXBKINTENA isr
ScicRegs.SCIHBAUD = 0x0000;
ScicRegs.SCILBAUD = 0x001a; //25MHZ 115200bps
ScicRegs.SCIFFTX.all=0xE000;
ScicRegs.SCIFFRX.all=0x2028;//收取8个字符后进中断
ScicRegs.SCIFFCT.all=0x00;
ScicRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
//----------------------------------------------------
{// GPIO28-29设置成SCIA
GpioCtrlRegs.GPAPUD.bit.GPIO28=0; //使能GPIO28内部上拉电阻
GpioCtrlRegs.GPAPUD.bit.GPIO29=0; //使能GPIO29内部上拉电阻
GpioCtrlRegs.GPAQSEL2.bit.GPIO28=3; //异步输入
GpioCtrlRegs.GPAMUX2.bit.GPIO28=1; //GPIO28=SCIRXDA
GpioCtrlRegs.GPAMUX2.bit.GPIO29=1; //GPIO29=SCITXDA
//GPIO62设置成SCICRX
GpioCtrlRegs.GPBPUD.bit.GPIO62=0; //使能GPIO62内部上拉电阻
GpioCtrlRegs.GPBQSEL2.bit.GPIO62=3; //异步输入
GpioCtrlRegs.GPBMUX2.bit.GPIO62=1; //GPIO62=SCIRXDC
}
//----------------------------------------------------------------------
{
EALLOW;
PieVectTable.SCIRXINTC = &scicRxFifoIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
IER |=M_INT8;
PieCtrlRegs.PIEIER8.bit.INTx5=1; //PIE Group 8, INT5
}
//-----------------------------------------------------
中断函数接收数据
interrupt void scicRxFifoIsr(void)
{
Uint16 j;
DINT;
for(j = 0; j < 8; j++)
{
scicTempBuf[j] = ScicRegs.SCIRXBUF.all; // Read data 一帧数据包包含16个字节
}
scicRecIntFlag = 1; //接收中断标志
ScicRegs.SCIFFRX.bit.RXFFOVRCLR = 1; // Clear Overflow flag
ScicRegs.SCIFFRX.bit.RXFFINTCLR = 1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all |= 0x080; // Issue PIE ack
EINT;
}
//----------------------------------------------
主循环中处理数据