zhangmangui 发表于 2014-1-20 16:29
interrupt void SCITXINTA_ISR(void) // SCI-A
{
unsigned char ReceivedAChar;
搞定了,多谢斑竹回答,好像是一个在中断里,最先没有关闭总中断,但是感觉这也不是什么问题
把代码贴出来吧
#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
#define BAUDSTEP 10
void scia_init(void);
void scib_init(void);
void scia_xmit(int a);
void scib_xmit(int a);
void scia_AutobaudLock(void);
void error(int);
interrupt void rxaint_isr(void);
Uint16 LoopCount;
Uint16 ReceivedCount;
Uint16 ErrorCount;
Uint16 SendChar;
Uint16 ReceivedAChar;
Uint16 ReceivedBChar;
Uint16 BRRVal;
Uint16 Buff[10] = {0x55, 0xAA, 0xF0, 0x0F, 0x00, 0xFF, 0xF5, 0x5F, 0xA5, 0x5C};
void main(void)
{
Uint16 i;
InitSysCtrl();
EALLOW;
GpioMuxRegs.GPFMUX.all=0x0030; // Select GPIOs to be Scia pins
GpioMuxRegs.GPGMUX.all=0x0030; // Select GPIOs to be Scib pins
EDIS;
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.RXAINT = &rxaint_isr;
EDIS;
scia_init(); // Initalize SCIA
scib_init(); // Initalize SCIB
LoopCount = 0;
ErrorCount = 0;
ReceivedCount=0;
SendChar=0;
PieCtrl.PIEIER9.all = 0x0001; // Enable all SCIA RXINT interrupt SCI B don't enable
IER |= 0x0100; // enable PIEIER9, and INT9 cpu intertupt
EINT;
for (BRRVal = 0x00f3; BRRVal < (Uint32)0xFFFF; BRRVal+=BAUDSTEP)
{
//SCIB has a known baud rate. SCIA will autobaud to match
ScibRegs.SCIHBAUD = (BRRVal >> 8);//host
ScibRegs.SCILBAUD = (BRRVal);
scia_AutobaudLock();
// scib_xmit('A');
while(ScibRegs.SCIRXST.bit.RXRDY != 1) { }
ReceivedBChar = 0;
ReceivedBChar = ScibRegs.SCIRXBUF.bit.RXDT;
// ReceivedBChar = ScibRegs.SCIRXBUF.all
if(ReceivedBChar != 'A')
{
error(0);
}
for(i= 0; i<=9; i++)
{
SendChar = Buff;
scib_xmit(SendChar);
while(ScibRegs.SCIRXST.bit.RXRDY != 1)
{
asm(" NOP");
}
ReceivedBChar = 0;
ReceivedBChar = ScibRegs.SCIRXBUF.bit.RXDT;
if(ReceivedBChar != SendChar)
error(1);
}
} // Repeat for next BRR setting
for(;;)
{
asm(" NOP");
}
}
interrupt void rxaint_isr(void) // SCI-A
{
// Insert ISR Code here
DINT;//关闭总中断
// If we were autobaud detecting, we must clear CDC
if(SciaRegs.SCIFFCT.bit.ABD == 1)
{
SciaRegs.SCIFFCT.bit.ABDCLR = 1;
SciaRegs.SCIFFCT.bit.CDC = 0;// Check received character - should be 'A' IF not "a" the program will into the
//scia_AutobaudLock()
ReceivedAChar = 0;
// ScibRegs.SCIRXBUF.bit.RXDT='A';
ReceivedAChar = SciaRegs.SCIRXBUF.bit.RXDT;
// ReceivedAChar = SciaRegs.SCIRXBUF.all;
if(ReceivedAChar != 'A')
{
error(2);
}
else scia_xmit(ReceivedAChar);
}
// This was not autobaud detect
else
{
// Check received character against sendchar
ReceivedAChar = 0;
ReceivedAChar = SciaRegs.SCIRXBUF.all;
if(ReceivedAChar != SendChar)
{
error(3);
}
else scia_xmit(ReceivedAChar);
}
SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1; // clear Receive interrupt flag ABD SRT 1 will cause FIFO中断(TXINT)。
//SciaRegs.SCIFFCT.bit.CDC = 0;
SciaRegs.SCIFFRX.bit.RXFIFORESET=0;
SciaRegs.SCIFFRX.bit.RXFIFORESET=1;
ReceivedCount++;
PieCtrl.PIEACK.all = PIEACK_GROUP9;
EINT;
}
void error(int ErrorFlag)
{
ErrorCount++;
/*asm(" ESTOP0"); // Uncomment to stop the test here 出错时,则停止运行
for (;;);*/
}
// SCIA 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void scia_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
// Reset FIFO's
SciaRegs.SCIFFTX.all=0x8000;
SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
//SciaRegs.SCICTL2.all =0x0003;
// SciaRegs.SCIHBAUD = 0;
//SciaRegs.SCILBAUD = 0xF3;
SciaRegs.SCICTL2.bit.RXBKINTENA =1;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
void scib_init()
{
ScibRegs.SCIFFTX.all=0x8000;
// 1 stop bit, No parity, 8-bit character
// No loopback
ScibRegs.SCICCR.all = 0x0007;
// Enable TX, RX, Use internal SCICLK
ScibRegs.SCICTL1.all = 0x0003;
// SCIB has a known baud rate. SCIA will autobaud to match
//ScibRegs.SCIHBAUD = 0;
//ScibRegs.SCILBAUD = 0xf3;
// Disable RxErr, Sleep, TX Wake,
// Diable Rx Interrupt, Tx Interrupt
ScibRegs.SCICTL2.all = 0x0000;
// Relinquish SCI-A from reset
ScibRegs.SCICTL1.all = 0x0023;//重启SCI
//return;
}
// Transmit a character from the SCI-A'
void scia_xmit(int a)
{
SciaRegs.SCITXBUF=a;
}
// Transmit a character from the SCI-B'
void scib_xmit(int a)
{
ScibRegs.SCITXBUF=a;
}
void scia_AutobaudLock()
{
Uint32 i;
SciaRegs.SCICTL1.bit.SWRESET = 0;
SciaRegs.SCICTL1.bit.SWRESET = 1;
// Must prime baud register with >= 1
SciaRegs.SCIHBAUD = 0;
SciaRegs.SCILBAUD = 1;
SciaRegs.SCIFFCT.bit.ABDCLR = 1;
SciaRegs.SCIFFCT.bit.CDC = 1;
while(SciaRegs.SCIFFCT.bit.CDC== 1)
{
for(i = 1; i<= 0x0FFFFFF; i++)
{
// asm(" NOP");
}
if(SciaRegs.SCIFFCT.bit.CDC == 1)
// for(;;)
scib_xmit('A'); // host transmits 'A'
}
//return;
}
//===========================================================================
// No more.
//===========================================================================
谢谢斑竹了。。
|