Created Sun, 19 Oct 2014 08:05:08 +0000 by salwan
Sun, 19 Oct 2014 08:05:08 +0000
Hi guys , I'm salwan this is first time use chipkit , now i have adxl345 gyro project i used analog devices chipkit driver with uno32 but the loading couldn't complete , please can you help me ? code below
/***************************************************************************//**
* @file ADXL345 sketch.
* @brief Demo project for ADXL345 using MPIDE Serial Monitor.
* @author Dan Nechita
********************************************************************************
* Copyright 2012(c) Analog Devices, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* - The use of this software may or may not infringe the patent rights
* of one or more patent holders. This license does not release you
* from the requirement that you obtain separate licenses from these
* patent holders to use this software.
* - Use of the software either in source or binary form, must be run
* on or directly connected to an Analog Devices Inc. component.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
********************************************************************************
* SVN Revision: 699
*******************************************************************************/
/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <ADXL345.h>
#include <DSPI.h>
#include <Wire.h>
/******************************************************************************/
/************************ Constants Definitions *******************************/
/******************************************************************************/
/*! List of available commands */
const char* commandsList[] = {"help?",
"communication=",
"communication?",
"acceleration?",
"interrupts?"
};
const char* commandsDescription[] = {
" - Displays all available commands.",
" - Selects the communication interface. Accepted values: 0(I2C),1(SPI).",
" - Displays the selected communication interface.",
" - Displays the acceleration on XYZ axis.",
" - Displays the state of the interrupts."};
/******************************************************************************/
/************************ Variables Definitions *******************************/
/******************************************************************************/
ADXL345 myADXL345;
/*! Variables used for console operations */
char commandsNumber = (sizeof(commandsList) / sizeof(const char*));
char receivedCommand[20];
char invalidCommand = 0;
char commandType = 0;
char command = 0;
char displayCommand = 0;
double commandParam = 0;
/*! Variables holding information about the device */
double x = 0; /*!< X-axis's output data in g. */
double y = 0; /*!< Y-axis's output data in g. */
double z = 0; /*!< Z-axis's output data. */
unsigned char intSource = 0; /*!< Value of the ADXL345_INT_SOURCE register. */
unsigned char commDevice = 0; /*!< Communication protocol(SPI or I2C). */
unsigned char accOn = 0; /*!< Status of measurement process. */
/*! Temporary variables */
unsigned long samplesNr = 0; /*!< Number of samples read from the device. */
char tempString [40];
/***************************************************************************//**
* @brief Reads one command from UART.
*
* @param command - Read command.
*
* @return None.
*******************************************************************************/
void CONSOLE_GetCommand(char* command)
{
unsigned char receivedChar = 0;
unsigned char charNumber = 0;
while(receivedChar != 0x0D)
{
if (Serial.available() > 0)
{
receivedChar = Serial.read();
command[charNumber++] = receivedChar;
}
}
command[charNumber] = 0;
}
/***************************************************************************//**
* @param receivedCommand - Received command.
* @param expectedCommand - Expected command.
* @param commandParameter - Command parameter.
*
* @return commandType - Type of the command.
* Example: 0 - Commands don't match.
* 1 - Write command.
* 2 - Read command.
*******************************************************************************/
unsigned char CONSOLE_CheckCommands(char* receivedCommand,
const char* expectedCommand,
double* commandParameter)
{
unsigned char commandType = 1;
unsigned char charIndex = 0;
unsigned char parameterString[5] = {0, 0, 0, 0, 0};
unsigned char parameterIndex = 0;
while((expectedCommand[charIndex] != '?') &&
(expectedCommand[charIndex] != '=') &&
(commandType != 0))
{
if(expectedCommand[charIndex] != receivedCommand[charIndex])
{
commandType = 0;
}
charIndex++;
}
if(commandType != 0)
{
if(expectedCommand[charIndex] == '=')
{
if(receivedCommand[charIndex] == '=')
{
charIndex++;
while(receivedCommand[charIndex] != 0x0D)
{
parameterString[parameterIndex] = receivedCommand[charIndex];
charIndex++;
parameterIndex++;
}
*commandParameter = atof((const char*)parameterString);
}
else
{
commandType = 0;
}
}
if(expectedCommand[charIndex] == '?')
{
if(receivedCommand[charIndex] == '?')
{
commandType = 2;
}
else
{
commandType = 0;
}
}
}
return commandType;
}
/***************************************************************************//**
* @brief Setup function.
*
* @return none.
*******************************************************************************/
void setup()
{
Serial.begin(9600);
if(myADXL345.Init())
{
Serial.println("ADXL345 OK");
}
else
{
Serial.println("ADXL345 Error");
}
}
/***************************************************************************//**
* @brief Loop function.
*
* @return none.
*******************************************************************************/
void loop()
{
/*! Wait a command from the user. */
CONSOLE_GetCommand(receivedCommand);
invalidCommand = 0;
/*! Check if the received command identifies as one of the command list. */
for(command = 0; command < commandsNumber; command++)
{
commandType = CONSOLE_CheckCommands(receivedCommand,
commandsList[command],
(double*)&commandParam);
/*! Count the commands that are invalid. */
if(commandType == 0)
{
invalidCommand++;
}
else
{
switch(command)
{
case 0: /*!< "help?" command*/
Serial.println("Available commands:");
for(displayCommand = 0; displayCommand < commandsNumber;
displayCommand++)
{
Serial.print(commandsList[displayCommand]);
Serial.println(commandsDescription[displayCommand]);
}
break;
case 1: /*!< "communication=" command*/
/*! Validate parameter */
commandParam = constrain(commandParam, 0, 1);
commDevice = (char)commandParam;
myADXL345.SetCommunication(commDevice);
/*! Send feedback to user */
Serial.print(commandsList[command]);
if(commDevice == I2C_COMMUNICATION)
{
Serial.println("I2C");
}
else
{
Serial.println("SPI");
}
/*! Configure device*/
myADXL345.SetTapDetection(ADXL345_SINGLE_TAP |
ADXL345_DOUBLE_TAP, /*!< Tap type. */
ADXL345_TAP_X_EN, /*!< Axis control. */
0x64, /*!< Tap duration.--10 */
0x20, /*!< Tap latency.--10 */
0x40, /*!< Tap window. */
0x10, /*!< Tap threshold. */
0x00); /*!< Interrupt Pin. */
myADXL345.SetFreeFallDetection(0x01, /*!< Free-fall detection enabled. */
0x05, /*!< Free-fall threshold. */
0x14, /*!< Time value for free-fall detection. */
0x00); /*!< Interrupt Pin. */
myADXL345.SetPowerMode(1); /*!< Measure mode. */
break;
case 2: /*!< "communication?" command*/
/*! Send the requested value to user */
Serial.print(commandsList[command - 1]);
if(commDevice == I2C_COMMUNICATION)
{
Serial.println("I2C");
}
else
{
Serial.println("SPI");
}
break;
case 3: /*!< "acceleration?" command*/
accOn = 1;
break;
case 4: /*!< "interrupts?" command*/
/*! Read the requested value from the device */
intSource = myADXL345.GetRegisterValue(ADXL345_INT_SOURCE);
/*! Send the requested value to user */
if((intSource & ADXL345_SINGLE_TAP) != 0)
{
Serial.println("Single Tap");
}
if((intSource & ADXL345_DOUBLE_TAP) != 0)
{
Serial.println("Double Tap");
}
if((intSource & ADXL345_FREE_FALL) != 0)
{
Serial.println("Free Fall");
}
break;
default:
break;
}/*!< End switch */
}/*!< End else */
}/*!< End for */
if(accOn)
{
samplesNr = 200;
while(samplesNr)
{
/*! Read the requested value from the device */
myADXL345.ReadAccel(&x,&y,&z);
/*! Send the requested value to user */
sprintf(tempString, "Xaxis=%.3f, Yaxis=%.3f, Zaxis=%.3f", x , y, z);
Serial.println(tempString);
samplesNr--;
}
accOn = 0;
/*! Measurement process has finished */
Serial.println("Measurement finished.");
}
if(invalidCommand == commandsNumber)
{
/*! Send feedback to user */
Serial.println("Invalid command");
}
}
Sun, 19 Oct 2014 10:04:45 +0000
And what is the actual error you get?
Sun, 19 Oct 2014 16:23:45 +0000
i got the loading bar in MPIDE goes 75% and stop until i rest uno32 . if my inserted code not clear below analog devices link http://wiki.analog.com/resources/tools-software/uc-drivers/microchip/adxl345
has chipkit driver i used it .