打印

F2812

[复制链接]
1683|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wurg|  楼主 | 2011-4-23 19:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
F2812, pi, TE, se, gp
哪位高人帮忙指点,我用F2812芯片,串口A正常,但串口B,收发都不正常,下面是程序;
哪里有错?
void main(void)
{
unsigned int k=0;
/*初始化系统*/
InitSysCtrl();
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE中断*/
InitPieCtrl();
/*初始化PIE中断矢量表*/
InitPieVectTable();

/*初始化SCIA寄存器*/
    InitSci();
    for(i = 0; i < 100; i++)
    {
     Sci_VarRx[i] = 0;
    }
    i = 0;
    j = 0;
    Send_Flag_A = 0;
Send_Flag_B = 0;
   
    #if SCIA_INT
/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
//PieVectTable.TXAINT = &SCITXINTA_ISR;
//PieVectTable.RXAINT = &SCIRXINTA_ISR;
PieVectTable.TXAINT = &SCITXINTA_ISR;
PieVectTable.RXAINT = &SCIRXINTA_ISR;

PieVectTable.TXBINT = &SCITXINTB_ISR;
PieVectTable.RXBINT = &SCIRXINTB_ISR;
EDIS;   // This is needed to disable write to EALLOW protected registers
/*开中断*/
IER |= M_INT9;
#endif
EINT;   // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{

  
  if((SciaTx_Ready() == 1)&& (Send_Flag_A == 1))
  {
   SciaRegs.SCITXBUF =Sci_VarRx[i];
   Send_Flag_A = 0;
   i++;
   if(i == j)
   {
    i = 0;
    j = 0;
   }
  }
  //
  if((ScibTx_Ready() == 1)&& (Send_Flag_B == 1))
  {
   ScibRegs.SCITXBUF =Sci_VarRx[i];
   Send_Flag_B = 0;
   i++;
   if(i == j)
   {
    i = 0;
    j = 0;
   }
  }
   
  #if !SCIA_INT
  
   if(SciaRx_Ready() == 1)
   {
    Sci_VarRx[j] = SciaRegs.SCIRXBUF.all;
    Send_Flag_A = 1;
    j++;
    if(j == 100)
    {
     j = 0;
    }
   }
  
   if(ScibRx_Ready() == 1)
   {
    Sci_VarRx[j] = ScibRegs.SCIRXBUF.all;
    Send_Flag_B = 1;
    j++;
    if(j == 100)
    {
     j = 0;
    }
   }
  #endif
}
}  
void InitSci(void)
{
// Initialize SCI-A:
*UART_MODE = 0x44;
EALLOW;
GpioMuxRegs.GPFMUX.all=0;
GpioMuxRegs.GPFMUX.bit.SCIRXDA_GPIOF5 =1;
GpioMuxRegs.GPFMUX.bit.SCITXDA_GPIOF4 =1;
EDIS;
/* loopback   8 bit data */
SciaRegs.SCICCR.all = 0x07;

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

SciaRegs.SCIHBAUD = 0x00;
SciaRegs.SCILBAUD = 0xF3;

SciaRegs.SCICTL1.all = 0x23;

PieCtrl.PIEIER9.bit.INTx1 = 1;
PieCtrl.PIEIER9.bit.INTx2 = 1;
//tbd...
  // Initialize SCI-B:
//tbd...
EALLOW;
GpioMuxRegs.GPGMUX.all=0;
GpioMuxRegs.GPGMUX.bit.SCIRXDB_GPIOG5 =1;
GpioMuxRegs.GPGMUX.bit.SCITXDB_GPIOG4 =1;
EDIS;
// loopback   8 bit data
ScibRegs.SCICCR.all = 0x07;

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

ScibRegs.SCIHBAUD = 0x00;
ScibRegs.SCILBAUD = 0xF3;

ScibRegs.SCICTL1.all = 0x23;

PieCtrl.PIEIER9.bit.INTx3 = 1;
PieCtrl.PIEIER9.bit.INTx4 = 1;
}
/********************************************************************************
name: int SciaTx_Ready(void)
input: none
output: i 1: ready
   0: busy
*********************************************************************************/
int SciaTx_Ready(void)
{
unsigned int i;
if(SciaRegs.SCICTL2.bit.TXRDY == 1)
{
  i = 1;
}
else
{
  i = 0;
}
return(i);
}
int ScibTx_Ready(void)
{
unsigned int i;
if(ScibRegs.SCICTL2.bit.TXRDY == 1)
{
  i = 1;
}
else
{
  i = 0;
}
return(i);
}
/********************************************************************************
name: int SciaRx_Ready(void)
input: none
output: i 1: new data
   0: none
*********************************************************************************/
int SciaRx_Ready(void)
{
unsigned int i;
if(SciaRegs.SCIRXST.bit.RXRDY == 1)
{
  i = 1;
}
else
{
  i = 0;
}
return(i);
}
int ScibRx_Ready(void)
{
unsigned int i;
if(ScibRegs.SCIRXST.bit.RXRDY == 1)
{
  i = 1;
}
else
{
  i = 0;
}
return(i);
}
//---------------------------------------------------------------------------
// SCI-A Default ISRs:
interrupt void SCIRXINTA_ISR(void)     // SCI-A
{
PieCtrl.PIEACK.bit.ACK9 = 1;
if(SciaRx_Ready() == 1)
{
  Sci_VarRx[j] = SciaRegs.SCIRXBUF.all;
  Send_Flag_A = 1;
  j++;
  if(j == 100)
  {
   j = 0;
  }
}
EINT;
}
interrupt void SCITXINTA_ISR(void)     // SCI-A
{
PieCtrl.PIEACK.bit.ACK9 = 1;
EINT;
}

//---------------------------------------------------------------------------
// SCI-B Default ISRs:
//
interrupt void SCIRXINTB_ISR(void)     // SCI-B
{
  // Insert ISR Code here
  // To recieve more interrupts from this PIE group, acknowledge this interrupt
   PieCtrl.PIEACK.all = PIEACK_GROUP9;
if(ScibRx_Ready() == 1)
{
  Sci_VarRx[j] = ScibRegs.SCIRXBUF.all;
  Send_Flag_B = 1;
  j++;
  if(j == 100)
  {
   j = 0;
  }
}
}
interrupt void SCITXINTB_ISR(void)     // SCI-B
{
  // Insert ISR Code here
  // To recieve more interrupts from this PIE group, acknowledge this interrupt
    PieCtrl.PIEACK.all = PIEACK_GROUP9;
EINT;
}


//===========================================================================
// No more.
//===========================================================================

相关帖子

沙发
米其林r| | 2011-4-30 16:35 | 只看该作者
不懂啊!

使用特权

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

本版积分规则

26

主题

40

帖子

0

粉丝