View Single Post
  #1   Spotlight this post!  
Unread 01-14-2010, 12:07 PM
wt200999's Avatar
wt200999 wt200999 is offline
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 321
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Help with 2010 Accelerometer & I2C

I am trying to implement the kit accelerometer, and I started by basing it off of the HiTechncCompass class from last years code. (I can't find the newest version, but I doubt that class has changed). The problem I am having is when I try to initialize the I2C in my robot constructor, the constructor does not finish and the robot stops responding. The console output from the serial port also does not give me any errors either. Here is the class I started, with simple functions just to see what I can get out of it:

I2CAccel.h
Code:
#ifndef __I2CACCEL__
#define __I2CACCEL__

#include "SensorBase.h"

class I2C;

class I2CAccel : public SensorBase
{
	public:
		I2CAccel(UINT32 ModuleSlot);
		~I2CAccel();
		float Get();
		
	private:
		static const kAddress = 0x3A;
		static const kReadAddress = 0x3B;
		static const kPowerSaving = 0x08;
		static const kPowerCtrl = 0x2D;
		
		I2C* m_i2c;
};

#endif
I2CAccel.cpp
Code:
#include "I2CAccel.h"
#include "DigitalModule.h"
#include "I2C.h"

I2CAccel::I2CAccel(UINT32 slot)
	: m_i2c (NULL)
{
        //Somewhere on these 3 lines it fails...
	DigitalModule *module = DigitalModule::GetInstance(slot);
	m_i2c = module->GetI2C(kAddress);
	
	m_i2c->Write(kPowerSaving,kPowerCtrl);
}

I2CAccel::~I2CAccel()
{
	delete m_i2c;
	m_i2c = NULL;
}

float I2CAccel::Get()
{
	UINT16 value;
	m_i2c->Read(kReadAddress, sizeof(value), (UINT8 *)&value);

	return (float)value;
}
I was wondering if anyone else has gotten theirs working?
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
Reply With Quote