This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430F5529:DMA 问题

Guru**** 2589280 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1051621/msp430f5529-dma-issue

器件型号:MSP430F5529

大家好、

#include <msp430.h>
#include <stdint.h>
#include<stdio.h>
#include<math.h>
#define PI 3.1415926535897932384626433832795028841971               //Defines the circumferential rate value 
#define FFT_N 128                                                   //Defines the number of points for the benefit leaf transformation 
struct compx {float real,imag;};                                    //Define a complex structure 
struct compx s[FFT_N];                                              //Ft input and output: Start with S[1] and customize by size 
int i=0;
float        adcresult;
unsigned int     *point_1=NULL;
unsigned int DMA_DST[16];                       // ADC conversion result is stored in this variable
void adcdma()
{
    P1OUT &= ~BIT0;                           // P1.0 clear
    P1DIR |= BIT0;                            // P1.0 output
    P5SEL |= BIT7;                            // P5.7/TB1 option select
    P5DIR |= BIT7;                            // Output direction
    P6SEL |= BIT0;                            // Enable A/D channel A0

    //Setup Timer B0
    TBCCR0 = 0xFFFE;
    TBCCR1 = 0x8000;
    TBCCTL1 = OUTMOD_3;                       // CCR1 set/reset mode
    TBCTL = TBSSEL_2+MC_1+TBCLR;              // SMCLK, Up-Mode

    // Setup ADC12
    ADC12CTL0 = ADC12SHT0_0+ADC12MSC+ADC12ON;// Sampling time, MSC, ADC12 on
    ADC12CTL1 = ADC12SHS_3+ADC12CONSEQ_2;     // Use sampling timer; ADC12MEM0
                                              // Sample-and-hold source = CCI0B =
                                              // TBCCR1 output
                                              // Repeated-single-channel
    ADC12MCTL0 = ADC12SREF_0+ADC12INCH_0;     // V+=AVcc V-=AVss, A0 channel
    ADC12CTL0 |= ADC12ENC;

    // Setup DMA0
    DMACTL0 = DMA0TSEL_24;                    // ADC12IFGx triggered
    DMACTL4 = DMARMWDIS;                      // Read-modify-write disable
    DMA0CTL &= ~DMAIFG;
    DMA0CTL = DMADT_4+DMAEN+DMADSTINCR_3+DMAIE; // Rpt single tranfer, unchanged dst, Int
    DMA0SZ = 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);
}


/*******************************************************************
Function prototype:struct compx EE(struct compx b1,struct compx b2)
Function function :Multiply two complex numbers 
Input parameters: Two complex numbers a,b defined in a combination 
Output parameters: The product of a and b, which is output in a combination 
*******************************************************************/
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);
}
/*****************************************************************
Function prototype :void FFT(struct compx *xin,int N)
Function function function: Fast Fourier transform on the entered complex array (FFT)
Input Parameters: * the first address pointer of the complex xin structure, struct type 
*****************************************************************/
void FFT(struct compx *xin)
{
  int f,m,nv2,nm1,i,k,l,j=0;
  struct compx u,w,t;

   nv2=FFT_N/2;                  //The variable address operation, which turns the natural order into the reverse order, uses the red algorithm 
   nm1=FFT_N-1;
   for(i=0;i<nm1;i++)
   {
    if(i<j)                    //If i<j, the address is changed 
     {
      t=xin[j];
      xin[j]=xin[i];
      xin[i]=t;
     }
    k=nv2;                    //The next reverse order of j is required 
    while(k<=j)               //If k<=j, the highest bit of j is 1 
     {
      j=j-k;                 //Change the highest bit to 0 
      k=k/2;                 //K/2, compare the next high, and so on, compare one by one until a bit is 0 
     }
   j=j+k;                   //Changed 0 to 1 
  }

  {
   int le,lei,ip;                            //FFT core, which uses a butterfly operation to complete the FFT operation 
    f=FFT_N;
   for(l=1;(f=f/2)!=1;l++)                  //Computes the value of l, which is the number of butterfly stages 
           ;
  for(m=1;m<=l;m++)                         //Control the number of butterfly junction stages 
   {                                        //M represents the class m butterfly, l is the total number of butterfly stages l=log(2)N. 
    le=2<<(m-1);                            //Le butterfly junction distance, the butterfly junction of the class m butterfly phase from the le point 
    lei=le/2;                               //The distance of two points in the same butterfly junction 
    u.real=1.0;                             //U is the butterfly node operating coefficient, with an initial value of 1 
    u.imag=0.0;
    w.real=cos(PI/lei);                     //W is the coefficient quotient, which is the current coefficients versus the previous coefficients 
    w.imag=-sin(PI/lei);
    for(j=0;j<=lei-1;j++)                   //The control calculates different types of butterfly knots, which are butterfly knots with different coefficients 
     {
      for(i=j;i<=FFT_N-1;i=i+le)            //Control the same butterfly junction operation, which is the same butterfly junction with the same coefficient 
       {
        ip=i+lei;                           //I, ip represents the two nodes participating in the butterfly operation 
        t=EE(xin[ip],u);                    //Butterfly operation, see the equation for details 
        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);                           //To change the coefficients for the next butterfly operation 
     }
   }
  }

}
int main(void)
{
  WDTCTL = WDTPW+WDTHOLD;                   // Hold WDT
  adcdma();
  while(!ADC12BUSY==1);
  point_1=&DMA_DST;
  adcresult=*point_1/1638.4;
    for(i=0;i<FFT_N;i++)                           //Assign values to the structure 
    {
        //adcresult=DMA_DST/1638.4;
       //s[i].real=adcresult;
    s[i].imag=0;                                //The imaginary part is 0 
    }

          FFT(s);                                        //For fast benefit leaf changes 

          for(i=0;i<FFT_N;i++)  {                         //The modulus value of the result after the change is stored in the real part of the complex number 
          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 0
      P1OUT ^= BIT0;                        // Toggle P1.0 - PLACE BREAKPOINT HERE AND CHECK DMA_DST VARIABLE
      break;
    case 4: break;                          // DMA1IFG = DMA Channel 1
    case 6: break;                          // DMA2IFG = DMA Channel 2
    case 8: break;                          // DMA3IFG = DMA Channel 3
    case 10: break;                         // DMA4IFG = DMA Channel 4
    case 12: break;                         // DMA5IFG = DMA Channel 5
    case 14: break;                         // DMA6IFG = DMA Channel 6
    case 16: break;                         // DMA7IFG = DMA Channel 7
    default: break;
  }
}

问题:现在无法推导出 DMA 的值、无法将其分配给变量。

您可以帮助检查此案例吗? 谢谢!

此致、

樱桃