[SOLVED] ADC not working in SES, same code works in IAR.

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] ADC not working in SES, same code works in IAR.

    I'm doing a project in SES writing in C/C++ code for the Atmel SAM3X8E on an arduino due. I'm trying do an ADC in order to read data from an anemometer but i can't get it to work. When I change IDE to IAR the exact same code works perfectly fine, but in SES it doesn't seem to even start en conversion. It get stuck in the while loop since no conversion was completed. The project was started with the SAM3 package. I've tried all sorts of things with the code but nothing seems to work. The code builds and compiles without any errors. I would be really grateful for any help i can get!


    Code in SES:

    C Source Code

    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. #include "SAM3.h"
    4. unsigned int val = 0;
    5. void main(void) {
    6. SystemInit();
    7. PMC->PMC_PCER0 = 1 << 11; //Enable pheripal clock Port A
    8. PMC->PMC_PCER1 = 1<<5; //Enable pheripal clock for ADC Controller
    9. REG_PIOA_PER = 3<<3; //Enable analog pin 5 and 6
    10. REG_ADC_MR = 1<<9; //Set prescaler rate
    11. while (1){
    12. REG_ADC_CHER = 1<<1; //Enable channel register for CH1
    13. REG_ADC_CR = 1<<1; //Start conversion
    14. while((REG_ADC_ISR & 1<<1) != 1<<1) //Check end of conversion on CH1
    15. val = REG_ADC_CDR1; //Get data from Channel Data Register 1
    16. printf("%d \n", val); //Print value
    17. }
    18. }
    Display All

    The post was edited 1 time, last by gustav ().

  • Hello,

    Thank you for your inquiry.
    Such an issue is not known to us.
    Are you certain it is the same code and sources that you use in IAR? Because in that case it would also work in Embedded Studio.
    Do you use the same CMSIS files in both IDEs? Make sure your setup is really identical in that regard.
    Enabling target specific peripherals always works the same if the target hardware is the same. How is explained in the chips documentation.

    Best regards,
    Nino
    Please read the forum rules before posting: Forum Rules

    Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Nino,

    Thanks for the answer!
    I should have mentioned that I'm not using the same CMSIS files so that might of course be where the problem lies. Although this, I don't what to use the files from IAR since I've already worked a bit on this project. I only tested the same code in IAR to make sure that the code works fine. So I narrowed the problem to missing something that needs to be done in SES before doing an ADC or that there's an issue with the SystemInit() funtion or the startup files.

    Since I've only added the SAM3 package for this project it seems weird that the ADC wouldn't work with the defualt files?
    If there's a working example of an ADC in SES this might help with finding the differences.

    Here are the files used in the project:
  • Hello,

    gustav wrote:

    Since I've only added the SAM3 package for this project it seems weird that the ADC wouldn't work with the defualt files?
    If there's a working example of an ADC in SES this might help with finding the differences.
    The packages are sourced from the CMSIS files provided by the silicon vendors that usually test their chips features. In this case the ADC feature does not seem to be working with this particular version of CMSIS files.
    We are currently updating some packages, including the SAM3 package (which according to Microchip is deprecated and split into 5 new packages...).
    To be informed when the packages get updated you can subscribe here:
    segger.com/notification/subscribe.php?prodid=196

    General information on how to enable the ADC bare metal without the CMSIS functions is explained in the chips reference manual. Currently I assume that a step is simply missing for the ADC to be enabled or clocked. Please understand that we can't provide further assistance in that matter as this is a target related function. If you have question about how to enable that feature we recommend contacting Microchip/Atmel support.

    Best regards,
    Nino
    Please read the forum rules before posting: Forum Rules

    Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.