Part Number:MSP430F5529
#include <msp430.h> #include <stdint.h> #include<stdio.h> #include<math.h> #define PI 3.1415926535897932384626433832795028841971//定义圆周率值 #define FFT_N 128//定义福利叶变换的点数 struct compx {float real,imag;};//定义一个复数结构 struct compx s[FFT_N];//FFT输入和输出:从S[1]开始存放,根据大小自己定义 int i=0; floatadcresult; unsigned int*point_1=NULL; unsigned int DMA_DST[16];// ADC conversion result is stored in this variable void adcdma() {P1OUT &= ~BIT0;// P1.0 clearP1DIR |= BIT0;// P1.0 outputP5SEL |= BIT7;// P5.7/TB1 option selectP5DIR |= BIT7;// Output directionP6SEL |= BIT0;// Enable A/D channel A0//Setup Timer B0TBCCR0 = 0xFFFE;TBCCR1 = 0x8000;TBCCTL1 = OUTMOD_3;// CCR1 set/reset modeTBCTL = TBSSEL_2+MC_1+TBCLR;// SMCLK, Up-Mode// Setup ADC12ADC12CTL0 = ADC12SHT0_0+ADC12MSC+ADC12ON;// Sampling time, MSC, ADC12 onADC12CTL1 = ADC12SHS_3+ADC12CONSEQ_2;// Use sampling timer; ADC12MEM0// Sample-and-hold source = CCI0B =// TBCCR1 output// Repeated-single-channelADC12MCTL0 = ADC12SREF_0+ADC12INCH_0;// V+=AVcc V-=AVss, A0 channelADC12CTL0 |= ADC12ENC;// Setup DMA0DMACTL0 = DMA0TSEL_24;// ADC12IFGx triggeredDMACTL4 = DMARMWDIS;// Read-modify-write disableDMA0CTL &= ~DMAIFG;DMA0CTL = DMADT_4+DMAEN+DMADSTINCR_3+DMAIE; // Rpt single tranfer, unchanged dst, IntDMA0SZ = 16;// DMA0 size = 16__data20_write_long((uintptr_t) &DMA0SA,(uintptr_t) &ADC12MEM0);// Source block address__data20_write_long((uintptr_t) &DMA0DA,(uintptr_t) &DMA_DST); } /******************************************************************* 函数原型:struct compx EE(struct compx b1,struct compx b2) 函数功能:对两个复数进行乘法运算 输入参数:两个以联合体定义的复数a,b 输出参数:a和b的乘积,以联合体的形式输出 *******************************************************************/ struct compx EE(struct compx a,struct compx b) { struct compx c; c.real=a.real*b.real-a.imag*b.imag; c.imag=a.real*b.imag+a.imag*b.real; return(c); } /***************************************************************** 函数原型:void FFT(struct compx *xin,int N) 函数功能:对输入的复数组进行快速傅里叶变换(FFT) 输入参数:*xin复数结构体组的首地址指针,struct型 *****************************************************************/ void FFT(struct compx *xin) {int f,m,nv2,nm1,i,k,l,j=0;struct compx u,w,t;nv2=FFT_N/2;//变址运算,即把自然顺序变成倒位序,采用雷德算法nm1=FFT_N-1;for(i=0;i<nm1;i++){if(i<j)//如果i<j,即进行变址{t=xin[j];xin[j]=xin[i];xin[i]=t;}k=nv2;//求j的下一个倒位序while(k<=j)//如果k<=j,表示j的最高位为1{j=j-k;//把最高位变成0k=k/2;//k/2,比较次高位,依次类推,逐个比较,直到某个位为0}j=j+k;//把0改为1}{int le,lei,ip;//FFT运算核,使用蝶形运算完成FFT运算f=FFT_N;for(l=1;(f=f/2)!=1;l++)//计算l的值,即计算蝶形级数;for(m=1;m<=l;m++)// 控制蝶形结级数{//m表示第m级蝶形,l为蝶形级总数l=log(2)Nle=2<<(m-1);//le蝶形结距离,即第m级蝶形的蝶形结相距le点lei=le/2;//同一蝶形结中参加运算的两点的距离u.real=1.0;//u为蝶形结运算系数,初始值为1u.imag=0.0;w.real=cos(PI/lei);//w为系数商,即当前系数与前一个系数的商w.imag=-sin(PI/lei);for(j=0;j<=lei-1;j++)//控制计算不同种蝶形结,即计算系数不同的蝶形结{for(i=j;i<=FFT_N-1;i=i+le)//控制同一蝶形结运算,即计算系数相同蝶形结{ip=i+lei;//i,ip分别表示参加蝶形运算的两个节点t=EE(xin[ip],u);//蝶形运算,详见公式xin[ip].real=xin[i].real-t.real;xin[ip].imag=xin[i].imag-t.imag;xin[i].real=xin[i].real+t.real;xin[i].imag=xin[i].imag+t.imag;}u=EE(u,w);//改变系数,进行下一个蝶形运算}}} } int main(void) {WDTCTL = WDTPW+WDTHOLD;// Hold WDTadcdma();while(!ADC12BUSY==1);point_1=&DMA_DST;adcresult=*point_1/1638.4;for(i=0;i<FFT_N;i++)//给结构体赋值{//adcresult=DMA_DST/1638.4;//s[i].real=adcresult;s[i].imag=0;//虚部为0}FFT(s);//进行快速福利叶变换for(i=0;i<FFT_N;i++) {//求变换后结果的模值,存入复数的实部部分s[i].real=sqrt(s[i].real*s[i].real+s[i].imag*s[i].imag);}// Destination single address__bis_SR_register(LPM0_bits + GIE);// LPM0 w/ interrupts__no_operation();// used for debugging } //------------------------------------------------------------------------------ // DMA Interrupt Service Routine //------------------------------------------------------------------------------ #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=DMA_VECTOR __interrupt void DMA_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(DMA_VECTOR))) DMA_ISR (void) #else #error Compiler not supported! #endif {switch(__even_in_range(DMAIV,16)){case 0: break;case 2:// DMA0IFG = DMA Channel 0P1OUT ^= BIT0;// Toggle P1.0 - PLACE BREAKPOINT HERE AND CHECK DMA_DST VARIABLEbreak;case 4: break;// DMA1IFG = DMA Channel 1case 6: break;// DMA2IFG = DMA Channel 2case 8: break;// DMA3IFG = DMA Channel 3case 10: break;// DMA4IFG = DMA Channel 4case 12: break;// DMA5IFG = DMA Channel 5case 14: break;// DMA6IFG = DMA Channel 6case 16: break;// DMA7IFG = DMA Channel 7default: break;} }
现在DMA的值并取不出来不能赋给一个变量
Cherry Zhou:
您好我们已收到您的问题并升级处理,如有答复将尽快回复您。谢谢!
,
Cherry Zhou:
您可以参考以下示例代码 MSP430F55xx_DMA_01,02,03 和 04.c 代码:
www.ti.com/…/slac300