1 Reply Latest reply on Oct 1, 2014 10:09 AM by SeyhanA_31

    We want to interface a 3 axis accelerometer with WICED-Wifi dev kit.the follwing is the code we came up with

      #include "wiced.h"

      #include "stdio.h"

       

       

       

      void application_start( )

      {

       

          int i;

       

          unsigned int x,y,z;

       

          wiced_init( );

       

          for(i=0;i<5000;i++)

          {

       

          wiced_result_t wiced_adc_init(wiced_adc_t adc1,uint32_t);

          wiced_result_t wiced_adc_take_sample( wiced_adc_t adc1, uint16_t* x );

       

          wiced_result_t wiced_adc_init(wiced_adc_t adc2, uint32_t );

          wiced_result_t wiced_adc_take_sample( wiced_adc_t adc2, uint16_t* y );

       

          wiced_result_t wiced_adc_init(wiced_adc_t adc3, uint32_t );

          wiced_result_t wiced_adc_take_sample( wiced_adc_t adc3, uint16_t* z );

       

          }

       

       

          x=x-338;

          y=y-338;

          z=z-338;

       

          printf("x=%d\ny=%d\nz=%d\n",x,y,z);

       

          wiced_result_t wiced_adc_deinit( wiced_adc_t adc1 );

          wiced_result_t wiced_adc_deinit( wiced_adc_t adc2 );

          wiced_result_t wiced_adc_deinit( wiced_adc_t adc3 );

       

       

      }

       

      We are getting a zero output for all x,y,z.

      Please help

        • 1. Re: We want to interface a 3 axis accelerometer with WICED-Wifi dev kit.the follwing is the code we came up with
          SeyhanA_31

          Hi,

           

          No need to keep initialize the adc, wiced_adc_init(...), before each reading of the adc value. Initialize the acd outside of the loop. Then the wiced_adc_take_sample(...) could be called to within a loop to read the ADC values.

           

          For sample code, you may look at the .../apps/demo/temp_control/temp_control.c for initializing the ADC then reading the ADC values.

           

          You may try following simple code as well.

          /*
           * Copyright 2014, Broadcom Corporation
           * All Rights Reserved.
           *
           * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
           * the contents of this file may not be disclosed to third parties, copied
           * or duplicated in any form, in whole or in part, without the prior
           * written permission of Broadcom Corporation.
           */
          
          /** @file
           *
           * ADC Read Sample
           *
           */
          
          #include <stdlib.h>
          #include "wiced.h"
          
          /******************************************************
           *                      Macros
           ******************************************************/
          
          /******************************************************
           *                    Constants
           ******************************************************/
          
          #define THERMISTOR_ADC        (WICED_THERMISTOR_JOINS_ADC) // thermistor on eval board
          #define ADC_READ_DELAYS        (200) // msec
          
          /******************************************************
           *                   Enumerations
           ******************************************************/
          
          /******************************************************
           *                 Type Definitions
           ******************************************************/
          
          /******************************************************
           *                    Structures
           ******************************************************/
          
          /******************************************************
           *               Static Function Declarations
           ******************************************************/
          
          /******************************************************
           *               Variable Definitions
           ******************************************************/
          
          /******************************************************
           *               Function Definitions
           ******************************************************/
          
          void application_start( )
          {
              wiced_init( );
              /* Initialize ADC */
              wiced_adc_init(THERMISTOR_ADC, 5);
              uint16_t adcValue;
              while(1)
              {
                  wiced_result_t result = wiced_adc_take_sample(THERMISTOR_ADC, &adcValue);
          
                  if (result == WICED_SUCCESS)
                      WPRINT_APP_INFO(("ADC Value read (thermistor)=0x%x\n", adcValue));
                  else
                      WPRINT_APP_INFO(("ADC read error=%d\n", result));
          
                  wiced_rtos_delay_milliseconds(ADC_READ_DELAYS);
              }
          }
          

           

          Seyhan