打印

2812 串口程序

[复制链接]
520|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Orchids|  楼主 | 2017-10-14 10:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
2812 串口程序


2812使用外部30M晶振,SysCtrlRegs.PLLCR = 0x02, SysCtrlRegs.HISPCP.all = 0x0001;
SysCtrlRegs.LOSPCP.all = 0x0002; SYSCLKOUT=30M

串口配置:
void InitSci(void)
{
// Initialize SCI-A:
//*UART_MODE = 0x44;//232mode
*UART_MODE = 0xDD;//422mode

EALLOW;
GpioMuxRegs.GPFMUX.all = 0x0030;
EDIS;
/* loopback 8 bit data */
SciaRegs.SCICCR.all = 0x07;

SciaRegs.SCICTL1.all = 0x03;
SciaRegs.SCICTL2.all = 0x03;

SciaRegs.SCIHBAUD = 0x00;
//SciaRegs.SCILBAUD = 0xf3; //150M,19200
SciaRegs.SCILBAUD = 0x30; //30M,19200

SciaRegs.SCICTL1.all = 0x23;

PieCtrl.PIEIER9.bit.INTx1 = 1;
PieCtrl.PIEIER9.bit.INTx2 = 1;
//tbd...

// Initialize SCI-B:
//tbd...
}

采用中断方式:
interrupt void SCIRXINTA_ISR(void)
{
unsigned int tempdata;
tempdata=SciaRegs.SCIRXBUF.all;
UartProcess(tempdata);


// *Rx++ = tempData;
// RX_INFO_FLAG.rx_all=1;

PieCtrl.PIEACK.bit.ACK9 = 1;
EINT;
}


interrupt void SCITXINTA_ISR(void) // SCI-A
{
length--;
if(length>0) SciaRegs.SCITXBUF=*Tx++;
else
{
Tx=0;
length=0;
}
PieCtrl.PIEACK.bit.ACK9 = 1;
EINT;
}


void SendData(unsigned char * pt)
{
Tx=pt;
length=9;
length--;
if(length>0) SciaRegs.SCITXBUF=*Tx++;
else
{
Tx=0;
length=0;
}
}


/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TXAINT = &SCITXINTA_ISR;
PieVectTable.RXAINT = &SCIRXINTA_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers


/*开中断*/
IER |= M_INT9;

EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

697

主题

993

帖子

4

粉丝