cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f207 ADC+TIMER+DMA / Poor Peripheral Library Examples

adrian
Associate III
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
34 REPLIES 34
tanguanzhong
Associate II
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);  ''
tanguanzhong
Associate II
Posted on March 07, 2015 at 07:25

My device is discovery F429. The project is use STM32 for AD high speed sampling only use one channel by TIM/DMA/ADC.  And I transfer the data to PC by USB.

The VCP of  USB for test is OK and can reach 500KB/s.

int main(void) {

  

    /* System Init */

    SystemInit();

 

 /* init for LCD */

    TM_ILI9341_Init();

 

 //Rotate LCD for 90 degrees

    TM_ILI9341_Rotate(TM_ILI9341_Orientation_Landscape_1);

    //FIll lcd with color

    TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA);

 

    //Put string with black foreground color and red background with 11x18px font

 gucPosition+=4;

    TM_ILI9341_Puts(4, gucPosition, ''LCD Init'', &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);

 

   

    /* Initialize ADC1 on channel 0, this is pin PA0 */

    TM_ADC_Init(ADC1, ADC_Channel_0);

   

    /* Initialize USB VCP */   

    TM_USB_VCP_Init();

    

    while (1) {

 

    }

}

tanguanzhong
Associate II
Posted on March 07, 2015 at 08:37

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6h1&d=%2Fa%2F0X0000000btN%2Fi2zYGpbIR5LpPwynxlaiO9xjqsQCskz4R0HcAIH1UCk&asPdf=false
tanguanzhong
Associate II
Posted on March 07, 2015 at 08:39

I modified the code based on yours and Tilen Majerle's. For I will used the ADC and the VCP of USB at the same time.

Posted on March 07, 2015 at 13:03

I modified the code based on yours and Tilen Majerle's. For I will used the ADC and the VCP of USB at the same time.

Yeah, not looking very familiar, maybe you should have started a new thread?

You seem to be doing an awful lot of processing in the interrupt for the rate you're pulling in samples, and waiting on other interrupts.

If you still don't see DMA TC interrupts, then you need to walk back up the dependency list. No DMA Interrupt, check that the DMA is occurring, check that the ADC is firing, check that the TIM is ticking, etc.

Lot of code that's not mine, using libraries I'm not using, looks to be hours of fun.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tanguanzhong
Associate II
Posted on March 07, 2015 at 16:10

Maybe you are right. The Interrupt is the problem source.

I will try to find it.

tanguanzhong
Associate II
Posted on April 11, 2015 at 11:09

The problem is fixed. The TIM2 is ok right now.

tanguanzhong
Associate II
Posted on April 11, 2015 at 11:34

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6fu&d=%2Fa%2F0X0000000bsz%2FIZ2OLpc74C57yd9ZLnVheeAWlR7hYTjaZKJEMQ0uAKo&asPdf=false
tanguanzhong
Associate II
Posted on April 11, 2015 at 11:43

But I still have a question. If I want to get the ADC data from buffer ADCOneConvertedValues[DMA_BUFFER] and send to computer by USB, how can I add code in this fuction?

void TM_ADC_DMA_IRQHandler(void)

{

  if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_HTIF0))

  {

 

 

 TM_DISCO_LedOff(LED_GREEN);

  

    // HalfTransferInterruptComplete Interrupt von DMA2 ist aufgetreten

    DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0);

       

  }

  else if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))

  {

 

   TM_DISCO_LedOn(LED_GREEN);

   

   

   

      // TransferInterruptComplete Interrupt von DMA2 ist aufgetreten

      DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);

  

 

  }

}
ameer
Associate II
Posted on August 30, 2015 at 14:53

Hi clive1. In your example the ADC conversion is completing at frequency 2KHz. i.e:

but you are triggering timer at 200KHz. Please help me understanding this logic. Thanks.