哪位高人帮忙指点,我用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.
//=========================================================================== |