完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
通信是SCIA 查询发送,中断接收。波特率19200。DSP和屏幕通信
先说收发的数据格式DSP一次收到的数据十个字,06 FF FF FF FF 00 98 E7 5E 11。屏幕会一直发送数据给DSP,不受控的发送,数据长度固定,但内容不固定。 DSP一次发送出去的数据13个字,03 06 02 00 50 00 80 00 98 00 66 A9 11,想要实现的是屏幕和DSP通信。 只单纯的DSP发送数据给屏幕,不接收屏幕的数据的话,没问题。 加上中断接收后,感觉DSP进中断了,但是发送给屏幕的数据就变乱了。 我是想这么实现的:1.初始化中断及SCI 2.开中断,开10级接收FIFO,满10个字中断一次,等中断两次后(因为我不知道是哪个码先进的FIFO,而我需要06作为起始码),开始处理数据 3.处理数据时先关SCIA接收中断,等处理完数据后再开SCIA接收中断。 实际情况是收到的数据是乱的,而且好像还影响了我的ADC中断,我的ADC中断等级(中断频率20KHz)比SCIA中断等级高。 求大神看看代码哪里出问题了!!!不胜感激!!!
|
|
相关推荐
14个回答
|
|
/****问题是单独发送可以,加了中断接收后,发送出来的数据乱了*********/
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File #include "AD7656.h" #include "math.h" #include "modbus.h" #include "control.h" //=========================================================================== unsigned int check=0,fup=0,fdown=0; int cs; int counter=0; int counter2=0; void InitEPwmMod(unsigned int lh_freq); //ePWM模块设置 void InitEPwm6ADC(double f);//AD采样电路出发脉冲生成,f为KHz interrupt void ADC_Int(void);//AD采样中断函数 interrupt void cpu_timer0_isr(void);//定时器0用于产生定时中断 //interrupt void scibTxFifoIsr(void); interrupt void sciaRxFifoIsr(void); void Gpio_select(void); void protect(void); void scia_fifo_init(void); //void scic_fifo_init(void); //void scib_fifo_init(void); //unsigned char sdataC[15]; unsigned char sdataA[40],sdataB[40],rdataB[40],pretc=0;//pretc=0 指示灯绿色 pretc=1 指示灯红色 Uint16 rdata_pointB; //SCIB接收数据检测 //unsigned int sdataA[40]; unsigned int sw1=0; Uint16 i=0,j=0,j1=0,k=0,a=2,b=2; // Send data for SCI-B Uint16 lh_1=0,lh_2=0,lh_3=150,lh_4=300,lh_5=300,lh_6=0; //Recive data from SCI-A unsigned int freq=300,freqt=300,sciRxcounter=0;// Initialization Frequency is 300Hz unsigned int range 0-65535 void main(void) { // int i=0; // Uint16 j=0; InitSysCtrl(); DELAY_US(10000L); DELAY_US(10000L); DELAY_US(10000L); InitEPwm1Gpio(); InitEPwm2Gpio(); Gpio_select(); InitEPwm6Gpio(); //AD_CLOCK InitEPwm6ADC(20.0); // Configure XINT1 XIntruptRegs.XINT1CR.bit.POLARITY = 0; // Falling edge interrupt XIntruptRegs.XINT1CR.bit.ENABLE = 1; // Enable XINT1 asm("NOP"); GpioDataRegs.GPBCLEAR.bit.GPIO60=1; InitXintf(); InitSciGpio(); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = &cpu_timer0_isr; EDIS; EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.SCIRXINTA = &sciaRxFifoIsr; // PieVectTable.SCITXINTA = &sciaTxFifoIsr; EDIS; EALLOW; //This is needed to write to EALLOW protected registers PieVectTable.XINT1 = &ADC_Int;//Set XINT1 in PIE EDIS; //This is needed to disable write to EALLOW protected registers EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS; // InitEPwmMod(); // freq=300; //Initialization output PWM 300Hz InitEPwmMod(freq); EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; InitCpuTimers();//初始化时钟 // ConfigCpuTimer(&CpuTimer0, 15000, 100000); //定时器0定时10s中断一次 ConfigCpuTimer(&CpuTimer0, 15000, 100000); CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0 CpuTimer0.InterruptCount = 0; //计数初值为0 PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE模块 PieCtrlRegs.PIEIER9.bit.INTx1 = 1;//PIE: Group 9 interrupt 1 SCI-A 接收中断 // PieCtrlRegs.PIEIER9.bit.INTx2 = 1;//PIE: Group 9 interrupt 2 SCI-A 发送中断 PieCtrlRegs.PIEIER1.bit.INTx4 = 1;//Enable INTn in the PIE: Group 1 interrupt 4 PieCtrlRegs.PIEIER1.bit.INTx7 = 1;// Enable TINT0 in the PIE: Group 1 interrupt 7 IER |= M_INT1;//Enable CPU INT1; IER |= M_INT9;//Enable CPU INT1; scia_fifo_init(); // scib_fifo_init(); // Init SCI-A B C // scic_fifo_init(); EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM for(i=0;i<40;i++) { sdataA[i]=sdataB[i]=rdataB[i]=0x00; } for(;;) //--------------------传送数据至上位机-------------------- { sdataB[0]=0x03; sdataB[1]=0x06; sdataB[2]=0x02; sdataB[3]=00; //01:16位数据高8位(人为设定地址位) sdataB[4]=Ig;//电压信号 //01:16位数据低8位(人为设定地址位) //sdataB[4]=100; sdataB[5]=00; //02高8位 sdataB[6]=freq*0.5; // 工作频率 02低8位 //sdataB[6]=300*0.5; sdataB[7]=00; //03高8位 sdataB[8]=pretc; //03低8位 //sdataB[8]=1; sdataB[9]=00; //04高8位 sdataB[10]=Ib;//04低8位 check=CRC16(sdataB,11);//CRC校验,check是16位,故应右移8位 sdataB[11]=(check>>8)&(0x00FF); sdataB[12]=check&0x00FF; freq=freqt; if(sciRxcounter == 2) { /*******以下6句共用于禁止SCI-A接收中断*************/ DINT;//禁止全局中断 INTM = 1 PieCtrlRegs.PIEIER9.bit.INTx1 = 0;//0-禁止接收中断 1-允许接收中断 for(lh_6=30;lh_6<35;lh_6++) sdataA[lh_6] = rdataB[lh_6];//5个空周期 PieCtrlRegs.PIEIFR9.bit.INTx1 = 0;//清除外设中断位 PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;//清除ACK位 EINT;//使能全局中断 INTM = 0 /*******以上6句共用于禁止SCI-A接收中断*************/ for(lh_6=0;lh_6<20;lh_6++) sdataA[lh_6] = rdataB[lh_6];//取回FIFO里的20个数据 for(lh_6=0;lh_6<20;lh_6++) { if(sdataA[lh_6] == 0x06) { lh_3 = sdataA[lh_6+6]; //取回来数据是100-250,表示200-500 lh_4 = lh_3*2; //数据回归到200-500 } } freqt = lh_4; //屏幕发回来的真实想要数值 if((freqt<501) && (freqt>199)) { if(freq != freqt) { lh_5 = freqt; InitEPwmMod(freqt); } } sciRxcounter =0; } DELAY_US(10000L); // it need to commented out for Frequence changes /*发送数据正常应该是03 02 06 00 Ig 00 Freq 00 pretc 00 Ib CRC CRC共13个字*/ /* 其中Freq 根据串口接收到的值改变*/ for(i=0;i<13;i++) { SciaRegs.SCITXBUF=sdataB[i];//SCITXBUF:SCIB发送器数据缓冲寄存器 } PieCtrlRegs.PIEIER9.bit.INTx1 = 1; //0-禁止接收中断 1-允许接收中断 } } interrupt void ADC_Int(void) { unsigned int i; // unsigned int fcnum,freq; //f is 20KHz 1 interrupt =0.05ms 10ms for key action once //counter num = 10/0.05 =200 for(i=0;i<7;i++) { SampleTable[i]= * AD_CHIPSEL; } GpioDataRegs.GPASET.bit.GPIO0=1; Ug= (SampleTable[0]+10) * 0.000305176;//Ug Ia= (SampleTable[1]-20) * 0.000305176* 11.11111;//Ia XIntruptRegs.XINT1CR.bit.ENABLE = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Enable to receive more interrupts from PIE1 GpioDataRegs.GPACLEAR.bit.GPIO0=1; protect(); } interrupt void sciaRxFifoIsr(void) { // unsigned int lh_i; if(sciRxcounter == 0) { for(lh_2=0;lh_2<10;lh_2++) { rdataB[lh_2] = (SciaRegs.SCIRXBUF.all) & 0x00FF; //读取数据 } } if(sciRxcounter == 1) { //sciRxcounter =0; for(lh_2=10;lh_2<20;lh_2++) { rdataB[lh_2] = (SciaRegs.SCIRXBUF.all) & 0x00FF; //读取数据 } } sciRxcounter++; /*正常收到的一组数据应该为06 FF FF FF FF 00 98 E7 5E 11 */ SciaRegs.SCIFFRX.bit.RXFFOVRCLR = 1; //清除溢出标志位 SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1; //清除中断标注位 SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1; PieCtrlRegs.PIEACK.all |= 0x100; } void scia_fifo_init() { 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.bit.TXINTENA =1;//使能发送中断 SciaRegs.SCICTL2.bit.RXBKINTENA =1;//使能接收中断 SciaRegs.SCIHBAUD =0x0003; //这两个值根据LSPCLK决定,LOSPCP来决定LSPCLK 现在LOSPCP=0,所以LSPCLK=SYSCLK/1 即150MHZ; SciaRegs.SCILBAUD =0x00D0;//SCI_PRD;波特率为19200--3D0 SciaRegs.SCICCR.bit.LOOPBKENA =0; // 1-Enable 0-disable loop back SciaRegs.SCIFFTX.all=0xCD28;// 发送FIFO有13个字 SciaRegs.SCIFFRX.all=0x0A21;// 接收FIFO有10个字 SciaRegs.SCIFFCT.all=0x00; SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; SciaRegs.SCIFFRX.bit.RXFIFORESET=1; } //-------------------------------------------------------------------------- //------------------------------NO MORE-------------------------------- //-------------------------------------------------------------------------- |
|
|
|
/****问题是单独发送可以,加了中断接收后,发送出来的数据乱了*********/
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File #include "AD7656.h" #include "math.h" #include "modbus.h" #include "control.h" //=========================================================================== unsigned int check=0,fup=0,fdown=0; int cs; int counter=0; int counter2=0; void InitEPwmMod(unsigned int lh_freq); //ePWM模块设置 void InitEPwm6ADC(double f);//AD采样电路出发脉冲生成,f为KHz interrupt void ADC_Int(void);//AD采样中断函数 interrupt void cpu_timer0_isr(void);//定时器0用于产生定时中断 //interrupt void scibTxFifoIsr(void); interrupt void sciaRxFifoIsr(void); void Gpio_select(void); void protect(void); void scia_fifo_init(void); //void scic_fifo_init(void); //void scib_fifo_init(void); //unsigned char sdataC[15]; unsigned char sdataA[40],sdataB[40],rdataB[40],pretc=0;//pretc=0 指示灯绿色 pretc=1 指示灯红色 Uint16 rdata_pointB; //SCIB接收数据检测 //unsigned int sdataA[40]; unsigned int sw1=0; Uint16 i=0,j=0,j1=0,k=0,a=2,b=2; // Send data for SCI-B Uint16 lh_1=0,lh_2=0,lh_3=150,lh_4=300,lh_5=300,lh_6=0; //Recive data from SCI-A unsigned int freq=300,freqt=300,sciRxcounter=0;// Initialization Frequency is 300Hz unsigned int range 0-65535 void main(void) { // int i=0; // Uint16 j=0; InitSysCtrl(); DELAY_US(10000L); DELAY_US(10000L); DELAY_US(10000L); InitEPwm1Gpio(); InitEPwm2Gpio(); Gpio_select(); InitEPwm6Gpio(); //AD_CLOCK InitEPwm6ADC(20.0); // Configure XINT1 XIntruptRegs.XINT1CR.bit.POLARITY = 0; // Falling edge interrupt XIntruptRegs.XINT1CR.bit.ENABLE = 1; // Enable XINT1 asm("NOP"); GpioDataRegs.GPBCLEAR.bit.GPIO60=1; InitXintf(); InitSciGpio(); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = &cpu_timer0_isr; EDIS; EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.SCIRXINTA = &sciaRxFifoIsr; // PieVectTable.SCITXINTA = &sciaTxFifoIsr; EDIS; EALLOW; //This is needed to write to EALLOW protected registers PieVectTable.XINT1 = &ADC_Int;//Set XINT1 in PIE EDIS; //This is needed to disable write to EALLOW protected registers EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS; // InitEPwmMod(); // freq=300; //Initialization output PWM 300Hz InitEPwmMod(freq); EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; InitCpuTimers();//初始化时钟 // ConfigCpuTimer(&CpuTimer0, 15000, 100000); //定时器0定时10s中断一次 ConfigCpuTimer(&CpuTimer0, 15000, 100000); CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0 CpuTimer0.InterruptCount = 0; //计数初值为0 PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE模块 PieCtrlRegs.PIEIER9.bit.INTx1 = 1;//PIE: Group 9 interrupt 1 SCI-A 接收中断 // PieCtrlRegs.PIEIER9.bit.INTx2 = 1;//PIE: Group 9 interrupt 2 SCI-A 发送中断 PieCtrlRegs.PIEIER1.bit.INTx4 = 1;//Enable INTn in the PIE: Group 1 interrupt 4 PieCtrlRegs.PIEIER1.bit.INTx7 = 1;// Enable TINT0 in the PIE: Group 1 interrupt 7 IER |= M_INT1;//Enable CPU INT1; IER |= M_INT9;//Enable CPU INT1; scia_fifo_init(); // scib_fifo_init(); // Init SCI-A B C // scic_fifo_init(); EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM for(i=0;i<40;i++) { sdataA[i]=sdataB[i]=rdataB[i]=0x00; } for(;;) //--------------------传送数据至上位机-------------------- { sdataB[0]=0x03; sdataB[1]=0x06; sdataB[2]=0x02; sdataB[3]=00; //01:16位数据高8位(人为设定地址位) sdataB[4]=Ig;//电压信号 //01:16位数据低8位(人为设定地址位) //sdataB[4]=100; sdataB[5]=00; //02高8位 sdataB[6]=freq*0.5; // 工作频率 02低8位 //sdataB[6]=300*0.5; sdataB[7]=00; //03高8位 sdataB[8]=pretc; //03低8位 //sdataB[8]=1; sdataB[9]=00; //04高8位 sdataB[10]=Ib;//04低8位 check=CRC16(sdataB,11);//CRC校验,check是16位,故应右移8位 sdataB[11]=(check>>8)&(0x00FF); sdataB[12]=check&0x00FF; freq=freqt; if(sciRxcounter == 2) { /*******以下6句共用于禁止SCI-A接收中断*************/ DINT;//禁止全局中断 INTM = 1 PieCtrlRegs.PIEIER9.bit.INTx1 = 0;//0-禁止接收中断 1-允许接收中断 for(lh_6=30;lh_6<35;lh_6++) sdataA[lh_6] = rdataB[lh_6];//5个空周期 PieCtrlRegs.PIEIFR9.bit.INTx1 = 0;//清除外设中断位 PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;//清除ACK位 EINT;//使能全局中断 INTM = 0 /*******以上6句共用于禁止SCI-A接收中断*************/ for(lh_6=0;lh_6<20;lh_6++) sdataA[lh_6] = rdataB[lh_6];//取回FIFO里的20个数据 for(lh_6=0;lh_6<20;lh_6++) { if(sdataA[lh_6] == 0x06) { lh_3 = sdataA[lh_6+6]; //取回来数据是100-250,表示200-500 lh_4 = lh_3*2; //数据回归到200-500 } } freqt = lh_4; //屏幕发回来的真实想要数值 if((freqt<501) && (freqt>199)) { if(freq != freqt) { lh_5 = freqt; InitEPwmMod(freqt); } } sciRxcounter =0; } DELAY_US(10000L); // it need to commented out for Frequence changes /*发送数据正常应该是03 02 06 00 Ig 00 Freq 00 pretc 00 Ib CRC CRC共13个字*/ /* 其中Freq 根据串口接收到的值改变*/ for(i=0;i<13;i++) { SciaRegs.SCITXBUF=sdataB[i];//SCITXBUF:SCIB发送器数据缓冲寄存器 } PieCtrlRegs.PIEIER9.bit.INTx1 = 1; //0-禁止接收中断 1-允许接收中断 } } interrupt void ADC_Int(void) { unsigned int i; // unsigned int fcnum,freq; //f is 20KHz 1 interrupt =0.05ms 10ms for key action once //counter num = 10/0.05 =200 for(i=0;i<7;i++) { SampleTable[i]= * AD_CHIPSEL; } GpioDataRegs.GPASET.bit.GPIO0=1; Ug= (SampleTable[0]+10) * 0.000305176;//Ug Ia= (SampleTable[1]-20) * 0.000305176* 11.11111;//Ia XIntruptRegs.XINT1CR.bit.ENABLE = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Enable to receive more interrupts from PIE1 GpioDataRegs.GPACLEAR.bit.GPIO0=1; protect(); } interrupt void sciaRxFifoIsr(void) { // unsigned int lh_i; if(sciRxcounter == 0) { for(lh_2=0;lh_2<10;lh_2++) { rdataB[lh_2] = (SciaRegs.SCIRXBUF.all) & 0x00FF; //读取数据 } } if(sciRxcounter == 1) { //sciRxcounter =0; for(lh_2=10;lh_2<20;lh_2++) { rdataB[lh_2] = (SciaRegs.SCIRXBUF.all) & 0x00FF; //读取数据 } } sciRxcounter++; /*正常收到的一组数据应该为06 FF FF FF FF 00 98 E7 5E 11 */ SciaRegs.SCIFFRX.bit.RXFFOVRCLR = 1; //清除溢出标志位 SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1; //清除中断标注位 SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1; PieCtrlRegs.PIEACK.all |= 0x100; } void scia_fifo_init() { 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.bit.TXINTENA =1;//使能发送中断 SciaRegs.SCICTL2.bit.RXBKINTENA =1;//使能接收中断 SciaRegs.SCIHBAUD =0x0003; //这两个值根据LSPCLK决定,LOSPCP来决定LSPCLK 现在LOSPCP=0,所以LSPCLK=SYSCLK/1 即150MHZ; SciaRegs.SCILBAUD =0x00D0;//SCI_PRD;波特率为19200--3D0 SciaRegs.SCICCR.bit.LOOPBKENA =0; // 1-Enable 0-disable loop back SciaRegs.SCIFFTX.all=0xCD28;// 发送FIFO有13个字 SciaRegs.SCIFFRX.all=0x0A21;// 接收FIFO有10个字 SciaRegs.SCIFFCT.all=0x00; SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; SciaRegs.SCIFFRX.bit.RXFIFORESET=1; } //-------------------------------------------------------------------------- //------------------------------NO MORE-------------------------------- //-------------------------------------------------------------------------- |
|
|
|
/****问题是单独发送可以,加了中断接收后,发送出来的数据乱了*********/
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File #include "AD7656.h" #include "math.h" #include "modbus.h" #include "control.h" //=========================================================================== unsigned int check=0,fup=0,fdown=0; int cs; int counter=0; int counter2=0; void InitEPwmMod(unsigned int lh_freq); //ePWM模块设置 void InitEPwm6ADC(double f);//AD采样电路出发脉冲生成,f为KHz interrupt void ADC_Int(void);//AD采样中断函数 interrupt void cpu_timer0_isr(void);//定时器0用于产生定时中断 //interrupt void scibTxFifoIsr(void); interrupt void sciaRxFifoIsr(void); void Gpio_select(void); void protect(void); void scia_fifo_init(void); //void scic_fifo_init(void); //void scib_fifo_init(void); //unsigned char sdataC[15]; unsigned char sdataA[40],sdataB[40],rdataB[40],pretc=0;//pretc=0 指示灯绿色 pretc=1 指示灯红色 Uint16 rdata_pointB; //SCIB接收数据检测 //unsigned int sdataA[40]; unsigned int sw1=0; Uint16 i=0,j=0,j1=0,k=0,a=2,b=2; // Send data for SCI-B Uint16 lh_1=0,lh_2=0,lh_3=150,lh_4=300,lh_5=300,lh_6=0; //Recive data from SCI-A unsigned int freq=300,freqt=300,sciRxcounter=0;// Initialization Frequency is 300Hz unsigned int range 0-65535 void main(void) { // int i=0; // Uint16 j=0; InitSysCtrl(); DELAY_US(10000L); DELAY_US(10000L); DELAY_US(10000L); InitEPwm1Gpio(); InitEPwm2Gpio(); Gpio_select(); InitEPwm6Gpio(); //AD_CLOCK InitEPwm6ADC(20.0); // Configure XINT1 XIntruptRegs.XINT1CR.bit.POLARITY = 0; // Falling edge interrupt XIntruptRegs.XINT1CR.bit.ENABLE = 1; // Enable XINT1 asm("NOP"); GpioDataRegs.GPBCLEAR.bit.GPIO60=1; InitXintf(); InitSciGpio(); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = &cpu_timer0_isr; EDIS; EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.SCIRXINTA = &sciaRxFifoIsr; // PieVectTable.SCITXINTA = &sciaTxFifoIsr; EDIS; EALLOW; //This is needed to write to EALLOW protected registers PieVectTable.XINT1 = &ADC_Int;//Set XINT1 in PIE EDIS; //This is needed to disable write to EALLOW protected registers EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS; // InitEPwmMod(); // freq=300; //Initialization output PWM 300Hz InitEPwmMod(freq); EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; InitCpuTimers();//初始化时钟 // ConfigCpuTimer(&CpuTimer0, 15000, 100000); //定时器0定时10s中断一次 ConfigCpuTimer(&CpuTimer0, 15000, 100000); CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0 CpuTimer0.InterruptCount = 0; //计数初值为0 PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE模块 PieCtrlRegs.PIEIER9.bit.INTx1 = 1;//PIE: Group 9 interrupt 1 SCI-A 接收中断 // PieCtrlRegs.PIEIER9.bit.INTx2 = 1;//PIE: Group 9 interrupt 2 SCI-A 发送中断 PieCtrlRegs.PIEIER1.bit.INTx4 = 1;//Enable INTn in the PIE: Group 1 interrupt 4 PieCtrlRegs.PIEIER1.bit.INTx7 = 1;// Enable TINT0 in the PIE: Group 1 interrupt 7 IER |= M_INT1;//Enable CPU INT1; IER |= M_INT9;//Enable CPU INT1; scia_fifo_init(); // scib_fifo_init(); // Init SCI-A B C // scic_fifo_init(); EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM for(i=0;i<40;i++) { sdataA[i]=sdataB[i]=rdataB[i]=0x00; } for(;;) //--------------------传送数据至上位机-------------------- { sdataB[0]=0x03; sdataB[1]=0x06; sdataB[2]=0x02; sdataB[3]=00; //01:16位数据高8位(人为设定地址位) sdataB[4]=Ig;//电压信号 //01:16位数据低8位(人为设定地址位) //sdataB[4]=100; sdataB[5]=00; //02高8位 sdataB[6]=freq*0.5; // 工作频率 02低8位 //sdataB[6]=300*0.5; sdataB[7]=00; //03高8位 sdataB[8]=pretc; //03低8位 //sdataB[8]=1; sdataB[9]=00; //04高8位 sdataB[10]=Ib;//04低8位 check=CRC16(sdataB,11);//CRC校验,check是16位,故应右移8位 sdataB[11]=(check>>8)&(0x00FF); sdataB[12]=check&0x00FF; freq=freqt; if(sciRxcounter == 2) { /*******以下6句共用于禁止SCI-A接收中断*************/ DINT;//禁止全局中断 INTM = 1 PieCtrlRegs.PIEIER9.bit.INTx1 = 0;//0-禁止接收中断 1-允许接收中断 for(lh_6=30;lh_6<35;lh_6++) sdataA[lh_6] = rdataB[lh_6];//5个空周期 PieCtrlRegs.PIEIFR9.bit.INTx1 = 0;//清除外设中断位 PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;//清除ACK位 EINT;//使能全局中断 INTM = 0 /*******以上6句共用于禁止SCI-A接收中断*************/ for(lh_6=0;lh_6<20;lh_6++) sdataA[lh_6] = rdataB[lh_6];//取回FIFO里的20个数据 for(lh_6=0;lh_6<20;lh_6++) { if(sdataA[lh_6] == 0x06) { lh_3 = sdataA[lh_6+6]; //取回来数据是100-250,表示200-500 lh_4 = lh_3*2; //数据回归到200-500 } } freqt = lh_4; //屏幕发回来的真实想要数值 if((freqt<501) && (freqt>199)) { if(freq != freqt) { lh_5 = freqt; InitEPwmMod(freqt); } } sciRxcounter =0; } DELAY_US(10000L); // it need to commented out for Frequence changes /*发送数据正常应该是03 02 06 00 Ig 00 Freq 00 pretc 00 Ib CRC CRC共13个字*/ /* 其中Freq 根据串口接收到的值改变*/ for(i=0;i<13;i++) { SciaRegs.SCITXBUF=sdataB[i];//SCITXBUF:SCIB发送器数据缓冲寄存器 } PieCtrlRegs.PIEIER9.bit.INTx1 = 1; //0-禁止接收中断 1-允许接收中断 } } interrupt void ADC_Int(void) { unsigned int i; // unsigned int fcnum,freq; //f is 20KHz 1 interrupt =0.05ms 10ms for key action once //counter num = 10/0.05 =200 for(i=0;i<7;i++) { SampleTable[i]= * AD_CHIPSEL; } GpioDataRegs.GPASET.bit.GPIO0=1; Ug= (SampleTable[0]+10) * 0.000305176;//Ug Ia= (SampleTable[1]-20) * 0.000305176* 11.11111;//Ia XIntruptRegs.XINT1CR.bit.ENABLE = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Enable to receive more interrupts from PIE1 GpioDataRegs.GPACLEAR.bit.GPIO0=1; protect(); } interrupt void sciaRxFifoIsr(void) { // unsigned int lh_i; if(sciRxcounter == 0) { for(lh_2=0;lh_2<10;lh_2++) { rdataB[lh_2] = (SciaRegs.SCIRXBUF.all) & 0x00FF; //读取数据 } } if(sciRxcounter == 1) { //sciRxcounter =0; for(lh_2=10;lh_2<20;lh_2++) { rdataB[lh_2] = (SciaRegs.SCIRXBUF.all) & 0x00FF; //读取数据 } } sciRxcounter++; /*正常收到的一组数据应该为06 FF FF FF FF 00 98 E7 5E 11 */ SciaRegs.SCIFFRX.bit.RXFFOVRCLR = 1; //清除溢出标志位 SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1; //清除中断标注位 SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1; PieCtrlRegs.PIEACK.all |= 0x100; } void scia_fifo_init() { 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.bit.TXINTENA =1;//使能发送中断 SciaRegs.SCICTL2.bit.RXBKINTENA =1;//使能接收中断 SciaRegs.SCIHBAUD =0x0003; //这两个值根据LSPCLK决定,LOSPCP来决定LSPCLK 现在LOSPCP=0,所以LSPCLK=SYSCLK/1 即150MHZ; SciaRegs.SCILBAUD =0x00D0;//SCI_PRD;波特率为19200--3D0 SciaRegs.SCICCR.bit.LOOPBKENA =0; // 1-Enable 0-disable loop back SciaRegs.SCIFFTX.all=0xCD28;// 发送FIFO有13个字 SciaRegs.SCIFFRX.all=0x0A21;// 接收FIFO有10个字 SciaRegs.SCIFFCT.all=0x00; SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; SciaRegs.SCIFFRX.bit.RXFIFORESET=1; } //-------------------------------------------------------------------------- //------------------------------NO MORE-------------------------------- //-------------------------------------------------------------------------- |
|
|
|
单方向发送没问题,双向收发有问题
|
|
|
|
|
|
1 条评论
|
|
请问你的问题怎么解决的?
|
|
|
|
问题得以解决就很好,送能从中学到东西!
|
|
|
|
|
|
|
|
你可以先断开 ,单独中断接受数据看看 是否正常
|
|
|
|
我已100ms定时发送8个字节的数,但在PC机上看只发送3个字节,将时间改为1s发送就没问题,请问这个是什么原因
|
|
|
|
跟你的波特率有关,发送一个字节所用的时间t=1/f(baudrate),发送八个字节所用理论时间8*t,但定时器的时间间隔要大于8*t |
|
|
|
一起学习共同进步
|
|
|
|
DSP28335 SCI通信问题!!!查询发中断收 [修改]
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
基于 DSP5509 进行数字图像处理中 Sobel 算子边缘检测的硬件连接电路图
2328 浏览 0 评论
680 浏览 0 评论
普中科技F28335开发板中,如何使用aic23播放由代码生成的正弦波
2765 浏览 0 评论
3525 浏览 1 评论
1192 浏览 1 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 03:20 , Processed in 0.790795 second(s), Total 78, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号