dsp28335的程序,我想实现的功能是将采集到的ADC的值通过SCI发送到上位机的串口调试工具上,希望能在界面显示我想读的数据~
Uint16 sdataB[2]; // Send data for SCI-B
//Uint16 rdataB[2]; // Received data for SCI-B
Uint16 ConversionCount=0;
Uint16 test=0;
Uint16 Voltage[3];
interrupt void adc_isr(void);
interrupt void scibTxFifoIsr(void);
//interrupt void scibRxFifoIsr(void);
void scib_fifo_init(void);
void ADC_init(void);
//void scib_xmit(Uint16 a);
//void scib_msg(Uint16 * msg);
Uint16 flag;
void main()
{
InitSysCtrl();
InitScibGpio();
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
InitXintf16Gpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitAdc();
scib_fifo_init();
ADC_init();
EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT = &adc_isr;
//PieVectTable.SCIRXINTB=&scibRxFifoIsr;
PieVectTable.SCITXINTB= &scibTxFifoIsr;
EDIS;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //adc中断1.6
//PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT3
PieCtrlRegs.PIEIER9.bit.INTx4=1; // 9.4发送中断
IER |= M_INT1; // Enable CPU Interrupt 1
IER |= M_INT9; // Enable CPU INT
EINT; // Enable Global interrupt INTM
ERTM; // For this example, init the ADC
AdcRegs.ADCTRL2.all = 0x2800;
for(;;);
}
interrupt void adc_isr(void)
{
ConversionCount++;
//Uint16 i;
// AdcRegs.ADCTRL2.all = 0x2800;
//while(AdcRegs.ADCST.bit.INT_SEQ1 == 0);
//for(i=0;i<3;i++)
//{
Voltage[0]=((AdcRegs.ADCRESULT0) >>4);
//}
// Voltage[1]=AdcRegs.ADCRESULT1 >>4;
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
DELAY_US(100);
//return;
}
interrupt void scibTxFifoIsr(void)
{
Uint16 i=0;
test++;
for(i=0; i<2; i++)
{
ScibRegs.SCITXBUF=sdataB; // Send data
//while(ScibRegs.SCICTL2.bit.TXRDY!=1){}
}
// text++;
ScibRegs.SCIFFTX.bit.TXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ACK
EINT;
}
/*interrupt void scibRxFifoIsr(void)
{
Uint16 i;
for(i=0;i<8;i++)
{
//ScibRegs.SCIRXBUF.all=Voltage1[ConversionCount];
sdataB=ScibRegs.SCIRXBUF.all; // Read data
}
ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
ScibRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack
}*/
void scib_fifo_init()
{
ScibRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScibRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
ScibRegs.SCICTL1.bit.TXENA=1; //发送使能
ScibRegs.SCICTL2.bit.TXINTENA =1;
// ScibRegs.SCICTL2.bit.RXBKINTENA =1;
ScibRegs.SCIHBAUD =0x01;
ScibRegs.SCILBAUD =0xE7 ;//9600
// ScibRegs.SCICCR.bit.LOOPBKENA =0; // Enable loop back
ScibRegs.SCIFFTX.all=0xC020; //发送FIFO为空时发生中断
// ScibRegs.SCIFFRX.all=0x0028;
ScibRegs.SCIFFCT.all=0x00;
ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset,禁止接收错误中断
ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;//重新使能接收寄存器
// ScibRegs.SCIFFRX.bit.RXFIFORESET=1;
}
void ADC_init()
// Specific ADC setup for this example:
{
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // 连续采样Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
// = 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)
// = 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)
// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL3.bit.SMODE_SEL=0; //顺序采样
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 级联模式(=0为双序列模式)
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // 采样ADCINA0和ADCINB0
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // 连续转换模式
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; // Enable Sequencer override feature
AdcRegs.ADCCHSELSEQ1.all = 0x0; // Initialize all ADC channel selects to A0
// AdcRegs.ADCCHSELSEQ2.all = 0x0;
// AdcRegs.ADCCHSELSEQ3.all = 0x0;
// AdcRegs.ADCCHSELSEQ4.all = 0x0;
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x0;
// convert and store in 8 results registers最大采样通道数为2,一次采两个通道,总共可采4个通道
// Start SEQ1 软件触发
AdcRegs.ADCTRL2.all = 0x2800;//0x2800; //AdcRegs.ADCTRL2.bit.SOC_SEQ1=1; 软件触发,中断使能
//0800为定时中断触发转换,中断使能。
} |