This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

unable to use adc1 in interrupt mode in stm32fx103rbt6

Hi, i am unable to use the adc in interrupt mode. following is the adc intialisation i have done. I am using adc 1 channel 14. I have added a IRQ handler :
/////////////////////////////////////////////////// void ADC_IRQHandler (void){ //fetch the value dataReg = (UNSIGNED16)ADC1->DR; dataReg++;

}
///////////////////////////////////////////////////

void adc_Init (void) {

// ptr = ADC_IRQHandler; RCC->APB2ENR |= (1<<9); /* enable periperal clock for ADC1 */

ADC1->SQR1 = 0x00000000; /* 1 conversions */ //ADC1->SQR1 |= 14<<5; ADC1->SQR3 = 14<<0;//(3<<10) | (2<<5) | (1<<0); /* set order to chn14 */ ADC1->SMPR2 = (5<< 9) | (5<<6) | (5<<3); /* set sample time (55,5 cycles) */

ADC1->CR1 = 0x00000100; /* use independant mode, SCAN mode */ ADC1->CR1 |= 1<<5; /* enable end of conversion interrupt */ ADC1->CR2 = 0x000E0000; /* data align right, cont. conversion */ ADC1->CR2 |= 0x0000001; /* data align right, cont. conversion */ /* EXTSEL = SWSTART */ /* enable ADC, No DMA mode */ ADC1->CR2 |= 0x00500000; /* start SW conversion */ }

///////////////////////
The entry of this IRQ is present in the stm32f10x.s file. when EOC bit gets set in the simulator my IRQ function does not get called.
Has any body used this functionality, if you have a sample project can you please mail it to me . my mail id is rohitd@kpitcummins.com .
we are using stm32fx103rbt6 processor.

thanks and regards
rohit

Parents
  • Hi,
    sorry for the error that happened in my previous post, i have re-edited the post.

    i am unable to use the adc in interrupt mode. following is the adc intialisation i have done. I am using adc 1 channel 14. I have added a IRQ handler :
    ///////////////////////////////////////////////////

    void ADC_IRQHandler  (void)
     {
        //fetch the value in global variable
        dataReg = (UNSIGNED16)ADC1->DR;
      }
    


    ///////////////////////////////////////////////////

    void adc_Init (void)
    {
      RCC->APB2ENR |= (1<<9);/*enable periperal clock
                              for ADC1      */
    
      ADC1->SQR1  = 0x00000000; /* 1 conversion */
      ADC1->SQR3  = 14<<0;   /* set order to chn14 */
      ADC1->SMPR2 = (5<< 9) | (5<<6) | (5<<3);/*set sample
                                              time*/
    
      ADC1->CR1   =  0x00000100;/*use independant mode*/
      ADC1->CR1   |=  1<<5;     /* enable end of
                                  conversion interrupt   */
      ADC1->CR2   =  0x000E0000;/* data align right*/
      ADC1->CR2   |=  0x0000001;
      ADC1->CR2  |=  0x00500000;/* start*/
      }
    

    ///////////////////////
    The entry of this IRQ is present in the stm32f10x.s file. when EOC bit gets set in the simulator my IRQ function does not get called.
    Has any body used this functionality, if you have a sample project can you please mail it to me . my mail id is rohitd@kpitcummins.com .
    we are using stm32fx103rbt6 processor.

Reply
  • Hi,
    sorry for the error that happened in my previous post, i have re-edited the post.

    i am unable to use the adc in interrupt mode. following is the adc intialisation i have done. I am using adc 1 channel 14. I have added a IRQ handler :
    ///////////////////////////////////////////////////

    void ADC_IRQHandler  (void)
     {
        //fetch the value in global variable
        dataReg = (UNSIGNED16)ADC1->DR;
      }
    


    ///////////////////////////////////////////////////

    void adc_Init (void)
    {
      RCC->APB2ENR |= (1<<9);/*enable periperal clock
                              for ADC1      */
    
      ADC1->SQR1  = 0x00000000; /* 1 conversion */
      ADC1->SQR3  = 14<<0;   /* set order to chn14 */
      ADC1->SMPR2 = (5<< 9) | (5<<6) | (5<<3);/*set sample
                                              time*/
    
      ADC1->CR1   =  0x00000100;/*use independant mode*/
      ADC1->CR1   |=  1<<5;     /* enable end of
                                  conversion interrupt   */
      ADC1->CR2   =  0x000E0000;/* data align right*/
      ADC1->CR2   |=  0x0000001;
      ADC1->CR2  |=  0x00500000;/* start*/
      }
    

    ///////////////////////
    The entry of this IRQ is present in the stm32f10x.s file. when EOC bit gets set in the simulator my IRQ function does not get called.
    Has any body used this functionality, if you have a sample project can you please mail it to me . my mail id is rohitd@kpitcummins.com .
    we are using stm32fx103rbt6 processor.

Children
  • Have you looked at the samples provided here by Keil?

    Have you looked at the samples provided by ST and included with the FWLib?

    You haven't shown any code for setting-up the NVIC...

    "please mail it to me . my mail id is rohitd@kpitcummins.com"

    This is a Public forum - not a free private consultancy service!

  • Excuse me ANDY , it seems u dont know english well , you dont know the differece betwwen the request and an order,if you have any problem in my post u may not reply to it, if you are a moderator u may delet the post.

    And there i sno need to reply to this post any further,not atleast you

  • and if i am asking for help, it means i have tried for a particular thing for long and ,dont want to waste more time on a thing which others may be knowing already. This is what forums are all about

  • 1) It is common practice to not request answers by mail. Why?
    a) It will not help anyone else with the same problem.
    b) Someone may respond with random garbage, and no other forum visitor will be able to notice, and warn you.

    2) Assuming that a request for help is the same as having spent significant time with a problem is way wrong. Some people do try themself before asking. Some people have web forums as the #1 step, followed by paste and compile as step #2 and #3. Because of this, it is important that _you_ supply complete information about your problem, and what you have tested, what information you have read, what results you expected, what results you did get...

    3) Visiting a forum will always open the possibility that you get answers you do not like. That is one of the things you are "paying" for requesting free help. Telling responders that they have a problem with their english is not a good way to get people to invest time in your problem. Other readers will see your comment and consider: Why bother...

  • Excuse me ANDY , it seems u dont know english well

    Ho, yeah.

    dont want to waste more time on a thing which others may be knowing already

    Ho, yeah.

  • So why did you not mention what you have tried?

    How can anyone avoid suggesting things you've already tried if you don't say what you've tried?!

    You asked for samples - I pointed you to two excellent sources of samples.

    You still haven't shown your NVIC setup code.

  • (Sorry for my bad English ability.)

    Hi rohit,

    Though, Andy Neil's responses are usually forthright and unsparing,
    but his responses are really helpful.

    From my understanding, Andy is a very good person, he is more than
    willing to help people.

    We all come from different countries and cultures, so that, We need
    more patience and tolerance, I believe.

    "Much of what looks like rudeness, is not intended to give offense.
    Rather, it's the product of the direct, cut-through-the-courtesy
    communications style that is natural to people who are more concerned
    about solving problems than making others feel warm and fuzzy."

    And I know that Andy did already provide help to you.

    So, why don't you just tell us something about the samples provided
    by Keil and ST; and show your NVIC source code?

    Please rohit.

  • Hello Rohit Deshpande,

    In your void adc_init(void) function you must configure ADC1->SMPR1 to set the sample time for channel 14.
    If you want to use the ADC Interrupt you must enable it in the NVIC NVIC->ISER[0] |= (1 << ADC1_2_IRQChannel);.
    Please see also Chap 5 Exceptions & Chap 8 Nested Vectored Interrupt Controller of the ARM Cortex-M3 Technical Reference Manual.

    You could take a look at the Blinky example in C:\Keil\ARM\Boards\Keil\MCBSTM32E\Blinky. This example uses also ADC channel 14 in interrupt mode.

    Best Regards,
    Martin Guenther

  • Hi all,

    Sorry Andy , yes i agree with john , i understand we come from two different cultures and nations too, and may be the case i took a wrong meaning out of the comments given by ANDY.

    I do understand that sending source code to my mail ID is too selfish , but my feeling behind asking for the source was because i thought no one would post the complete code over here in the forum.

    Sorry again for being too rude.

    I had intialised all the registers but still the interrupt was not getting generated, I was able to set a particular bit in the check box (of keil simulator)
    and then the interrupt would occur,but i was not uderstanding the location of this bit (In register).

    as told by marting and andy i tried looking in to the NVIC bits and my issue got solved.

    Thanks forum for helping me out of this issue ,and extremly sorry for being rude , and certainly this wont happen in future.

    Thanks and regards
    Rohit Deshpande