Simple ADC Scan Implementation
Antwort
17.03.16 14:10
Hello All,

I have quickly created code that makes use of the ADC Scan function.  It will currently read the ADC Channels 5 and 6 so you can quickly and easily see both channels on the extension board at the same time.  You can also easily expand this to scan more ADC channels by editing the macro NUMBER_OF_CHANNELS  and variable adc0_scaninit_conf.input in the scanAdcInit() function.  The code was created in XDK Workbench 1.5.1.  You should be able to start with the XDK Template project and replace the XdkApplicationTemplate.c file with the code below and start playing with it.

Enjoy!!

/**
 * This software is copyrighted by Bosch Connected Devices and Solutions GmbH, 2016.
 * The use of this software is subject to the XDK SDK EULA
 */

/* module includes ********************************************************** */

/* system header files */
#include <stdint.h>
#include <stdio.h>

/* additional interface header files */
#include "OS_operatingSystem_ih.h"
#include "em_cmu.h"
#include "ADC_ih.h"

/* own header files */

/* constant definitions ***************************************************** */
#define ONESECONDDELAY      UINT32_C(1000)       /* one second is represented by this macro */
#define TIMERBLOCKTIME      UINT32_C(0xffff)     /* Macro used to define blocktime of a timer */
#define TIMEBASE            UINT32_C(0)          /* Macro used to define the Timebase for the ADC */
#define ADCFREQUENCY        UINT32_C(9000000)    /* Macro Used to define the frequency of the ADC Clock */
#define NUMBER_OF_CHANNELS  UINT32_C(2)

/* local variables ********************************************************** */
OS_timerHandle_tp scanAdcTimerHandle;

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */
static void scanAdcInit(void);
static void scanAdc(OS_timerHandle_tp pxTimer);

/**
 * @brief Configure the ADC to scan multiple channels;
 *        Initialize and Start a time to scan the ADC
 */
static void scanAdcInit(void)
{
    /* Initialize Configuration ADC Structures */
    ADC_Init_TypeDef     adc0_init_conf     = ADC_INIT_DEFAULT;
    ADC_InitScan_TypeDef adc0_scaninit_conf = ADC_INITSCAN_DEFAULT;

    /* Enable Clocks for the ADC */
    CMU_ClockEnable(cmuClock_HFPER, true);
    CMU_ClockEnable(cmuClock_ADC0, true);

    /* Configure the ADC Initialization Structure */
    adc0_init_conf.timebase = ADC_TimebaseCalc(TIMEBASE);
    adc0_init_conf.prescale = ADC_PrescaleCalc(ADCFREQUENCY, TIMEBASE);
    ADC_Init(ADC0, &adc0_init_conf);

    /* Configure the ADC Scan Structure */
    adc0_scaninit_conf.reference = adcRefVDD;
    adc0_scaninit_conf.input     = ADC_SCANCTRL_INPUTMASK_CH5 |
                                   ADC_SCANCTRL_INPUTMASK_CH6;

    ADC_InitScan(ADC0, &adc0_scaninit_conf);

    /* Setup and Start the timer to scan the ADC Channels */
    scanAdcTimerHandle = OS_timerCreate(
        (const int8_t *) "ADC read", ONESECONDDELAY,
        OS_AUTORELOAD_ON, NULL, scanAdc);

    OS_timerStart(scanAdcTimerHandle, TIMERBLOCKTIME);
}

/**
 * @brief Timer Callback; Scans and prints out the ADC Channels' Values
 */
static void scanAdc(OS_timerHandle_tp pxTimer)
{
    /* Initialize the Variables */
    (void) (pxTimer);
    uint32_t _adc0ChData = 0;
    uint8_t _channelsScanned = 0;

    /* Start the ADC Scan */
    ADC_Start(ADC0, adcStartScan);

    for (_channelsScanned = 0; _channelsScanned < NUMBER_OF_CHANNELS; _channelsScanned++) {
        /* Wait for Valid Data */
        while (!(ADC0->STATUS & ADC_STATUS_SCANDV));

        /* Read the Scanned data */
        _adc0ChData = 0xFFF & ADC_DataScanGet(ADC0);
        printf("ADC Channel %ld = %ld\r\n", ((ADC0->STATUS & _ADC_STATUS_SCANDATASRC_MASK) >> _ADC_STATUS_SCANDATASRC_SHIFT), _adc0ChData);
    }
}

/* global functions ********************************************************* */


/**
 * @brief This is a template function where the user can write his custom application.
 *
 */
void appInitSystem(OS_timerHandle_tp xTimer)
{
    (void) (xTimer);
    scanAdcInit();
}

/** ************************************************************************* */
+1 (1 Stimme)
Simple ADC Scan Implementation
Antwort
17.03.16 23:31 als Antwort auf Christopher Koch.
Hello Chris,

thank you for sharing your work. We're really happy to see your post here!

Kind regards
Manuel
0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
19.07.16 12:33 als Antwort auf Christopher Koch.

Hey Chris,

I am attempting to build the code that you provided, and the following include statement is failing:


#include "OS_operatingSystem_ih.h"

Do I need to import that specific header file from somewhere else, or are you aware of another way to remedy this?

Thanks,

Joe

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
20.07.16 09:07 als Antwort auf Joe Nater.

Hello Joe,

the code that chris provided is deprecated and not updated to the latest XDK workbench 1.6. I updated the code to the workbench 1.6. Please check for further information the first post of chris.

/* module includes ********************************************************** */

/* system header files */
#include "BCDS_Basics.h"

#include <stdint.h>
#include <stdio.h>

/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

/* own header files */
#include "XdkApplicationTemplate.h"

#include "em_cmu.h"
#include "ADC_ih.h"

/* constant definitions ***************************************************** */

#define TIMER_AUTORELOAD_ON pdTRUE

#define ONESECONDDELAY      UINT32_C(1000)       /* one second is represented by this macro */
#define TIMERBLOCKTIME      UINT32_C(0xffff)     /* Macro used to define blocktime of a timer */
#define TIMEBASE            UINT32_C(0)          /* Macro used to define the Timebase for the ADC */
#define ADCFREQUENCY        UINT32_C(9000000)    /* Macro Used to define the frequency of the ADC Clock */
#define NUMBER_OF_CHANNELS  UINT32_C(2)

/* local variables ********************************************************** */

xTimerHandle scanAdcTimerHandle;

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */

/**
 * @brief Configure the ADC to scan multiple channels;
 *        Initialize and Start a time to scan the ADC
 */
static void scanAdcInit(void)
{
    /* Initialize Configuration ADC Structures */
    ADC_Init_TypeDef     adc0_init_conf     = ADC_INIT_DEFAULT;
    ADC_InitScan_TypeDef adc0_scaninit_conf = ADC_INITSCAN_DEFAULT;

    /* Enable Clocks for the ADC */
    CMU_ClockEnable(cmuClock_HFPER, true);
    CMU_ClockEnable(cmuClock_ADC0, true);

    /* Configure the ADC Initialization Structure */
    adc0_init_conf.timebase = ADC_TimebaseCalc(TIMEBASE);
    adc0_init_conf.prescale = ADC_PrescaleCalc(ADCFREQUENCY, TIMEBASE);
    ADC_Init(ADC0, &adc0_init_conf);

    /* Configure the ADC Scan Structure */
    adc0_scaninit_conf.reference = adcRefVDD;
    adc0_scaninit_conf.input     = ADC_SCANCTRL_INPUTMASK_CH5 |
                                   ADC_SCANCTRL_INPUTMASK_CH6;

    ADC_InitScan(ADC0, &adc0_scaninit_conf);

    /* Setup and Start the timer to scan the ADC Channels */
    scanAdcTimerHandle = xTimerCreate(
        (const char *) "ADC read", ONESECONDDELAY,
        TIMER_AUTORELOAD_ON, NULL, scanAdc);

    xTimerStart(scanAdcTimerHandle, TIMERBLOCKTIME);
}

/**
 * @brief Timer Callback; Scans and prints out the ADC Channels' Values
 */
static void scanAdc(xTimerHandle pxTimer)
{
    /* Initialize the Variables */
    (void) (pxTimer);
    uint32_t _adc0ChData = 0;
    uint8_t _channelsScanned = 0;

    /* Start the ADC Scan */
    ADC_Start(ADC0, adcStartScan);

    for (_channelsScanned = 0; _channelsScanned < NUMBER_OF_CHANNELS; _channelsScanned++) {
        /* Wait for Valid Data */
        while (!(ADC0->STATUS & ADC_STATUS_SCANDV));

        /* Read the Scanned data */
        _adc0ChData = 0xFFF & ADC_DataScanGet(ADC0);
        printf("ADC Channel %ld = %ld\r\n", ((ADC0->STATUS & _ADC_STATUS_SCANDATASRC_MASK) >> _ADC_STATUS_SCANDATASRC_SHIFT), _adc0ChData);
    }
}

/* global functions ********************************************************* */

/**
 * @brief This is a template function where the user can write his custom application.
 *
 */
void appInitSystem(xTimerHandle xTimer)
{
    (void) (xTimer);
    scanAdcInit();
}

/** ************************************************************************* */

 

Kind regards,

Franjo

+1 (1 Stimme)
RE: Simple ADC Scan Implementation
Antwort
17.01.18 14:24 als Antwort auf Franjo Stjepandic.

Hello All, 

i want to use the code from Christopher in the new version of the workbench (3.2). I replaced the module "ADC_ih.h" with "em_adc.h". It shows the error that "Field 'STATUS' could not be resolved". How could i solve the error? Is there adocumentation for reading in inputs with the XDK Gateway?

I hope you can help me.

King Regards

Matthias

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
17.01.18 17:28 als Antwort auf Matthias Dörr.

 

Hello Matthias,

First of all, welcome to the XDK community.

I assume, that the build of your project finishes without issues. The error regarding the field status, however is still there?

Am I right so far?

If that is correct, then you can safely ignore the error.

Only the indexing system of the XDK-Workbench is unable to find the correct link to this field. That is the reason, why the error Status could not be resolved is displayed. But as I earlier mentioned, you can safely ignore that, as long as the build finishes without errors and the compiler displays no red marked errors in the console.

Please let me know if that was helpful and do not hesitate to ask, if you have further questions.

Kind regards,
Franjo

 

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
10.06.18 14:43 als Antwort auf Franjo Stjepandic.

Hi folks,

 

I just encountered a similar problem like Matthias.

Some fields in the em_adc.h could not be resolved, as well as STATUS in my own application adcTest.c. But there are some "real" errors as well (see picture). Due to that I cannot flash the file to the xdk.

I created the application from the XdkApplicationTemplate and copied code from the XdkExtensionBus_Guide. So everything should be the same as in there

https://xdk.bosch-connectivity.com/documents/37728/219851/XDK110_ExtensionBus_Guide.pdf/ac16d8a7-470b-4e3c-9610-7a0885987451

 

Does someone kow what the problem is? Am I missing some imports?

 

Thanks in advance

Julian

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
11.06.18 12:26 als Antwort auf Julian Peters.
Hello Julian,

the semantic errors can be safely ignored.

The issue seems to lie with the compilation of one (or more) of the libraries. Could you please tell me which XDK-Workbench version you are using, and post the console log of a compilation attempt? The last 10-20 lines (including the duration) should hold the most relevant information.

Also, have you made any changes to the SDK? And could you tell me which code-snippets you copied from the guide, so that I may try to reproduce this issue?

Kind regards,
Franjo
0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
11.06.18 14:34 als Antwort auf Franjo Stjepandic.

Hello Franjo,

 

thanks for the fast reply.

I am Using the following version of the workbench:

Version            : 3.3.1
Build date        : 2018-03-21T13:17:04Z
Git Commit    : before_generator_refactoring-1127-g82b60d344

 

The problems with the em_adc.h seems to have solved by itself as I tried to recompile just now.

Still there is the STATUS "error" and a new warning with an invalid project path (see picture)

 

I copied the code from the section adc in the Extension bus guide:

 

/* system header files */
#include <stdio.h>
//#include <stdint.h>
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

/* own header files */
#include "adcTest.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"
#include "BCDS_Basics.h"
#include "em_adc.h"
#include "em_gpio.h"
//#include "em_cmu.h"
#include "BSP_BoardShared.h"
//#include "efm32gg_adc.h"

#define adcPin0        5
#define adcPin1        6

/* constant definitions ***************************************************** */

/* local variables ********************************************************** */

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */

/* global functions ********************************************************* */

void adcInit(int adcPin) {

    // configure Pin as input with Pull-Down
    GPIO_PinModeSet(gpioPortD, adcPin, gpioModeInputPull, 0);
    GPIO_PinOutClear(gpioPortD, adcPin);

    // configure adc
    ADC_InitSingle_TypeDef channelInit = ADC_INITSINGLE_DEFAULT;
    channelInit.reference = adcRef2V5;
    channelInit.resolution = adcRes12Bit;
    channelInit.input = adcSingleInpCh5;
    ADC_InitSingle(ADC0, &channelInit);
}

void adcReadSingle() {
    uint32_t AdcSample = 0;
    while ((ADC0->STATUS & (ADC_STATUS_SINGLEACT)) && (BSP_UNLOCKED == ADCLock));
    __disable_irq();
    ADCLock = BSP_LOCKED;
    __enable_irq();
    ADC_Start(ADC0, adcStartSingle);
    // Wait while conversion is active
    while (ADC0->STATUS & (ADC_STATUS_SINGLEACT));
    AdcSample = 0xFFF & ADC_DataSingleGet(ADC0);
    __disable_irq();
    ADCLock = BSP_UNLOCKED;
    __enable_irq();

}

/**
 * @brief This is a template function where the user can write his custom application.
 *
 */
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);


    adcInit(adcPin0);
    adcReadSingle();
}

 

 

 

Thanks in advance for your help

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
11.06.18 15:34 als Antwort auf Julian Peters.
Hello Julian,

I have tested your code as follows:

I created a new project and copied + pasted the code you posted into a new XDK Project.

To the project's makefile, I only added the line:
  -I${BCDS_BASE_DIR}/../SDK/xdk110/Platform/BSP/source
to the macro BCDS_XDK_INCLUDES on line 19, to fix the dependency with the header-file BSP_BoardShared.h .

The only two errors I encountered were the Semantic Errors regarding the unresolved variable STATUS . These errors do not make the compilation fail and you can safely supress them by adding the following comment to the line (it must be in the same line):
 
// @suppress("Field cannot be resolved")

But, as mentioned before, I did not receive any other errors, so I can not reproduce your issue properly.

Generally, it seems to be an issue with the SDK or with the project's Makefile. Have you made any changes to any of the makefiles or the project settings? If not, I would simply recommend to reinstall the XDK-Workbench, and to make sure it is located on an installation path without spaces.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
12.06.18 08:39 als Antwort auf Franjo Stjepandic.

Hello Franjo,

 

thanks for your reply.

I also created a new project and copied the code in it on a different PC where the xdk workbench worked fine all the time. But still there is the error.

So I started to put the code from the ADC Guide I mentioned before in my project step by step and compiling at each step, starting with the imports em_adc.h.

It compiles fine until I put the following line in the makefile (line 19):

export BCDS_XDK_INCLUDES = \-I$(BCDS_BASE_DIR)/sdk/xdk110/Platform/BSP/source/

At this time I haven't put in any other code in except from the imports

I also tried it with and without /sdk or /... , no change.

So this has to be the problem. I expect my path is somehow false. Where exactly does the macro -I$(BCDS_BASE_DIR) point to? Do you have any ideas what I could correct?

Is there a possibility to work around the BSP_BoardShared.h file?

My folder structre can be seen in the picture.

 

Thanks in advance

Julian

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
12.06.18 08:42 als Antwort auf Julian Peters.
Here are Console Log and Errors, I forgot to put in.
0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
12.06.18 11:48 als Antwort auf Julian Peters.
Hello Julian,

BCDS_BASE_DIR is pointing to C:\XDK-Workbench\XDK\SDK , which is the path to the SDK folder.

Given that path, you have to append /../SDK/xdk110/Platform/BSP/source/ to configure the correct includes.

As such, please use the path -I$(BCDS_BASE_DIR)/../SDK/xdk110/Platform/BSP/source/ or -I$(BCDS_BASE_DIR)/xdk110/Platform/BSP/source/ in your applications makefile.

And additionally, place this on the line below the export, instead of the same line, as shown below:
 
export BCDS_XDK_INCLUDES = \ 
           -I$(BCDS_BASE_DIR)/../SDK/xdk110/Platform/BSP/source/ 

The backslash at the end of the line indicates that the command is continued on the next line (since makefiles read only one command per line otherwise). Since you had that backslash in the same line, it was interpreted as part of the path, resulting in an Illegal Argument .

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
13.06.18 20:53 als Antwort auf Franjo Stjepandic.

Hi Franjo,

 

I am getting the following errors with the makefile lines

 

export BCDS_XDK_INCLUDES = \ 
           -I$(BCDS_BASE_DIR)/../SDK/xdk110/Platform/BSP/source/

Error see last one

 

strangely, when I put only 1 tab (4 spaces) before the -I$ I get the following Error

export BCDS_XDK_INCLUDES = \
    -I$(BCDS_BASE_DIR)/xdk110/Platform/BSP/source/

22:40:31 **** Incremental Build of configuration XDK Default for project adcVoltMeasureTest ****
mingw32-make debug
Makefile:20: *** recipe commences before first target.  Stop.

22:40:32 Build Finished (took 102ms)

 

export BCDS_XDK_INCLUDES = \
           -I$(BCDS_BASE_DIR)/../SDK/xdk110/Platform/BSP/source/

Building file C:/Users/julia/XDK-Workspace/adcVoltMeasureTest/source/adcVoltMeasureTest.c
arm-none-eabi-gcc: error:  : No such file or directory
application.mk:345: recipe for target 'C:/Users/julia/XDK-Workspace/adcVoltMeasureTest/debug/objects/adcVoltMeasureTest.o' failed
mingw32-make[1]: *** [C:/Users/julia/XDK-Workspace/adcVoltMeasureTest/debug/objects/adcVoltMeasureTest.o] Error 1
mingw32-make[1]: Leaving directory 'C:/XDK-Workbench/XDK/SDK/xdk110/Common'
Makefile:33: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2

22:44:57 Build Finished (took 2s.700ms)

 

 

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
13.06.18 20:55 als Antwort auf Julian Peters.

I got it now. I deleted the spaces/tabs before the -I$ and now it works.

Even if I put back the spaces it compiles fine. Problem solved

 

As a backup I just copied out the lines I needed from the "BSP_BoardShared.h" into my application file which also worked.

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
14.06.18 08:59 als Antwort auf Julian Peters.
Hello Julian,

I am glad to hear that you were able to make it work.

Please feel free to ask if you have any kind of further questions or concerns.

Kind regards,
Franjo
0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
08.10.18 12:11 als Antwort auf Franjo Stjepandic.

Hi,

I copied the code into a new project and it works fine. I also downloaded the data logger demo and now trying to combine these two codes. But if I include the ADC-Code to the data logger code, I get the error message "

Description Resource Path
expected identifier or '(' before numeric constant efm32gg_msc.h /DataLogger/SDK/xdk110/Libraries/EMlib/3rd-party/EMLib/Device/SiliconLabs/EFM32GG/Include

How can I fix this? I didn't change any Code in the file efm32gg_msc.h

 

Kind Regrads

Johannes

0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
09.10.18 14:31 als Antwort auf Johannes Kaiser.
Dear Johannes,

I assume that there might something went wrong during the copy process of the source code into the Data Logger demo. As such, changing the content of the interface efm32gg_msc.h should not be necessary.

Besides, the code you are referring in this thread is no longer up to date for the XDK-Workbench 3.4.0. As such, I recommend taking a look at the code snippets provided in the Extension Bus guide or within the XDK Knowledgebase .

Otherwise, if the error still persists I would ask you to provide an outline about how you embedded the ADC code within the Data Logger demo.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
14.10.18 15:31 als Antwort auf Franjo Stjepandic.
Dear Franjo,  thank you for your advice. I created a new project to test the ADC code, provided in the Extension Bus Guide. This is my code: 

 

/* additional interface header files */
#include "BCDS_Basics.h"
#include "BCDS_Assert.h"
#include "BCDS_TaskConfig.h"
#include "BCDS_CmdProcessor.h"
#include "FreeRTOS.h"
#include "timers.h"

#include "em_cmu.h"
#include "em_adc.h"
#include "em_gpio.h"
#include "BSP_BoardShared.h"

/* system header files */
#include <stdint.h>
#include <stdio.h>

/*local variables */
xTimerHandle scanAdcTimerHandle;

/*constant definitions */
#define TIMER_AUTORELOAD_ON pdTRUE

#define ONESECONDDELAY      UINT32_C(1000)       /* one second is represented by this macro */
#define TIMERBLOCKTIME      UINT32_C(0xffff)     /* Macro used to define blocktime of a timer */
#define TIMEBASE            UINT32_C(0)          /* Macro used to define the Timebase for the ADC */
#define ADCFREQUENCY        UINT32_C(9000000)    /* Macro Used to define the frequency of the ADC Clock */



static void scanAdc(xTimerHandle pxTimer)
{
    /* Initialize the Variables */
    (void) (pxTimer);
    uint32_t _adc0ChData = 0;

    while ((ADC0->STATUS & (ADC_STATUS_SCANACT)) && (BSP_UNLOCKED == ADCLock))
            ;
        __disable_irq();
        ADCLock = BSP_LOCKED;
        __enable_irq();
        ADC_Start(ADC0, adcStartScan);
        for (int channels = 0; channels < 2; channels++) {
            // Wait for Valid Data
            while (!(ADC0->STATUS & ADC_STATUS_SCANDV))
                ;
            // Read the Scanned data
               _adc0ChData = 0xFFF & ADC_DataScanGet(ADC0);
                printf("ADC Channel %ld = %ld\r\n", ((ADC0->STATUS & _ADC_STATUS_SCANDATASRC_MASK) >> _ADC_STATUS_SCANDATASRC_SHIFT), _adc0ChData);
        }
        __disable_irq();
        ADCLock = BSP_UNLOCKED;
        __enable_irq();
}

/**
 * @brief Configure the ADC to scan multiple channels;
 *        Initialize and Start a timer to scan the ADC
 */
static void scanAdcInit(void)
{
    ADC_Init_TypeDef     adc0_init_conf     = ADC_INIT_DEFAULT;
    ADC_InitScan_TypeDef scanInit = ADC_INITSCAN_DEFAULT;

    /* Configure ADC pins as input */
    GPIO_PinModeSet(gpioPortD, 5, gpioModeInputPull, 0);
    GPIO_PinOutClear(gpioPortD, 5);
    GPIO_PinModeSet(gpioPortD, 6, gpioModeInputPull, 0);
    GPIO_PinOutClear(gpioPortD, 6);

    /* Configure the ADC Initialization Structure */
    ADC_Init(ADC0, &adc0_init_conf);

    /* Configure the ADC Scan Structure */
    scanInit.reference = adcRef2V5;
    scanInit.resolution = adcRes12Bit;
    scanInit.input = ADC_SCANCTRL_INPUTMASK_CH5 | ADC_SCANCTRL_INPUTMASK_CH6;

    ADC_InitScan(ADC0, &scanInit);

    /* Setup and Start the timer to scan the ADC Channels */
    scanAdcTimerHandle = xTimerCreate(
        (const char *) "ADC read", ONESECONDDELAY,
        TIMER_AUTORELOAD_ON, NULL, scanAdc);

    xTimerStart(scanAdcTimerHandle, TIMERBLOCKTIME);
}


/* global functions ********************************************************* */

/**
 * @brief This is a template function where the user can write his custom application.
 *
 */
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    (void) ( CmdProcessorHandle);
    (void) (param2);
    scanAdcInit();
}

But when I flash it on my xdk, I just get one value of the ADC, then the program stops. How can I fix this? Kind regards, Johannes
0 (0 Stimmen)
RE: Simple ADC Scan Implementation
Antwort
16.10.18 15:09 als Antwort auf Johannes Kaiser.
Dear Johannes,

Thank you for providing your source code. I tested the source code you provided with a simple potentiometer and was able to found the issue, why it is not working.

In fact, you are declaring a variable called adc0_init_conf of the type ADC_Init_TypeDef and then you are passing the variable filled with default parameters into the function ADC_Init() . This is causing your issue, because the ADC is initialized every startup and the intilization with default parameters is interfering with the startup initialization.

To make it work, simply remove the declaration of the variable and the call of the function ADC_Init() .

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Stimmen)