Skip to main content
adrian
Associate III
April 24, 2013
Question

stm32f207 ADC+TIMER+DMA / Poor Peripheral Library Examples

  • April 24, 2013
  • 34 replies
  • 7013 views
Posted on April 24, 2013 at 11:19

Hi,

I'm looking to sample a signal (well, 2 actually - quadrature analog signals) at a fixed sample rate, but I'm baffled by the lack of any example in the Standard Peripheral Library on how to achieve this.

I would have thought that this would be a pretty standard example, i.e sample x points of a signal at y kHz and store result in memory location z.

Can anyone from ST comment on why such a basic (and imo fundamental) example is missing from the Standard Peripheral Library?

Does anybody else have an basic example of how this is achieved?  There are various incomplete snippets of code if you search in this forum, but elsewhere on the internet I've been able to find zilch.

I suspect I'm going to have to go read the manual in depth to figure this lot out...oh joy!

Many thanks.

Adrian
    This topic has been closed for replies.

    34 replies

    denis
    Associate III
    October 23, 2013
    Posted on October 23, 2013 at 16:08

    Turns out my asm 'skills' are even more absent than I thought..

    (And basic understanding of C arrays too ... urgh :\   dumb ass on my  part)

    Tesla DeLorean
    Guru
    October 23, 2013
    Posted on October 23, 2013 at 16:53

    Please don't delete posts it damages the integrity of the thread.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    denis
    Associate III
    October 23, 2013
    Posted on October 23, 2013 at 18:09

    sry , wanted to remove my stupid stuff

    Amel NASRI
    ST Technical Moderator
    October 25, 2013
    Posted on October 25, 2013 at 18:03

    Hello,

    Empty & repeated posts were removed to clean-up the whole discussion.

    -Mayla-

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
    Gulev.Borislav
    Explorer
    January 12, 2014
    Posted on January 12, 2014 at 18:20

    A fine example.

    My question is: Is it possible frequency of ADC module to connect to the pin for synchronization to an external device.

    For example

    T2_TRGO

     -> pin...

    Tesla DeLorean
    Guru
    January 12, 2014
    Posted on January 12, 2014 at 19:11

    You can get a TIM to clock from an external source, both edges I think, by there is some resynchronization latency. Set a Period = 1

    The DCMI does permit some parallel input clocking
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    tanguanzhong
    Visitor II
    March 6, 2015
    Posted on March 06, 2015 at 16:52

    void DMA2_Stream0_IRQHandler(void) // Called at 1 KHz for 200 KHz sample rate, LED Toggles at 500 Hz
    {
    /* Test on DMA Stream Half Transfer interrupt */
    if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_HTIF0))
    {
    /* Clear DMA Stream Half Transfer interrupt pending bit */
    DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0);
    /* Turn LED3 off: Half Transfer */
    STM_EVAL_LEDOff(LED3);
    // Add code here to process first half of buffer (ping)
    }
    /* Test on DMA Stream Transfer Complete interrupt */
    if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))
    {
    /* Clear DMA Stream Transfer Complete interrupt pending bit */
    DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
    /* Turn LED3 on: End of Transfer */
    STM_EVAL_LEDOn(LED3);
    // Add code here to process second half of buffer (pong)
    }
    }

    I used this code as above. I set a breakpoint in function

    DMA2_Stream0_IRQHandler. It seems to be called. but cannot get into this statement and the condition.

    if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))
    
     Can you give some possiable problems?
    

    Tesla DeLorean
    Guru
    March 6, 2015
    Posted on March 06, 2015 at 17:32

    Can you give some possible problems?

    Your debugger is interfering with the DMA registers/flags?

    Your reaction time is below 500 Hz?

    The timer stops, the DMA errors? Or neither actually stop?

    If you don't use a debugger, and you put a scope on the LED, do you see it toggle continuously?
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    tanguanzhong
    Visitor II
    March 7, 2015
    Posted on March 07, 2015 at 07:08

    Thanks your advice. So I make a test. If I set the breakpoint here for

    TM_ADC_DMA_IRQHandler();

    .

    void DMA2_Stream0_IRQHandler (void) {

      uint32_t events;

      events = (DMA2->LISR >>  0) & DMA_STREAM_FLAGS;

      DMA2->LIFCR = events <<  0;

      DMA2_Stream0_Event(events);

     

      //tgz

     

    TM_ADC_DMA_IRQHandler();

      //tgz

     

    } It can go into the ''if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))'' statement. And output information on LCD.

    tanguanzhong
    Visitor II
    March 7, 2015
    Posted on March 07, 2015 at 07:16

    /* need to call this function in DMA2_Stream0_IRQHandler in  */

     void TM_ADC_DMA_IRQHandler(void)

    {

     _INT  iAdcTemp = 0;

     _US i = 0;

     _UC ucBuff[512] = {0};

     

     //record the interrupt time

     gusTimer++;

     

     

    if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))

     {

      gucPosition+=10;  

      TM_ILI9341_Puts(10, gucPosition, ''------------interrupt-----------'', &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);  

      

      

     if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED)

     {

      gucPosition+=10;  

      //TM_ILI9341_Puts(10, gucPosition, ''------------2)usb is good-----------'', &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);  

      

      

      VCP_DataTx(ucBuff, 512);

     };

      

     }

     /* Clear DMA Stream Transfer Complete interrupt pending bit */

     DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);

      }

    But if I don't use the debugger and delete all the breakpoint. Only used the LCD for output. There is no information output for statement.

    ''TM_ILI9341_Puts(10, gucPosition, ''------------interrupt-----------'', &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);  ''