CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

driver for CMA3000 VTI technologies 3axis accelerometer I2C

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
ivan



Joined: 03 Apr 2008
Posts: 8
Location: Italy Rome

View user's profile Send private message

driver for CMA3000 VTI technologies 3axis accelerometer I2C
PostPosted: Sun Nov 15, 2009 10:53 am     Reply with quote

Hi to all
I write this driver for CMA3000 VTI technologies 3axis accelerometer in I2C mode this is only device I found work down to 1.8V. I hope can be useful for someone.
Code:

#ifndef pin_SDA
#define pin_SDA  PIN_e0
#define pin_SCL  PIN_e1
#endif
#use i2c(master,sda=pin_SDA,scl=pin_SCL)
//register
#define WHO_AM_I   0x00   //Identification register  R  Output
#define REVID      0x01   //ASIC revision ID, fixed in metal  R  Output
#define CTRL       0x02   //Configuration (por, operation modes) RW  Conf
#define STATUS     0x03   //Status (por, EEPROM parity)  R  Output
#define RSTR       0x04   //Reset Register  RW  Conf
#define INT_STATUS 0x05   //Interrupt status register  R  Output
#define DOUTX      0x06   //X channel output data register  R  Output
#define DOUTY      0x07   //Y channel output data register  R  Output
#define DOUTZ      0x08   //Z channel output data register  R  Output
#define MDTHR      0x09   //Motion detection threshold value register RW  Conf
#define MDFFTMR    0x0A   //Free fall and motion detection time register RW  Conf
#define FFTHR      0x0B   //Free fall threshold value register  RW  Conf
#define I2C_ADDR   0x0C   //I2C device address  R  Conf
//------------------------  0Dh-19h    Reserved     

int1 cma3k_ready()
{
   int1 ack;
   i2c_start();            // If the write command is acknowledged,
   ack = i2c_write(0x38);  // then the device is ready.
   i2c_stop();
   return !ack;
}

void write_cma3k(int8 adr,int8 data)
{
   while(!cma3k_ready());
   i2c_start();
   i2c_write(0x38);
   i2c_write(adr);
   i2c_write(data);
   i2c_stop();
}

int8 read_cma3k(int8 adr)
{
  int8 ret;
    while(!cma3k_ready());
   i2c_start();
   i2c_write(0x38);
   i2c_write(adr);
   i2c_start();
   i2c_write(0x39);
   ret=i2c_read(0);
   i2c_stop();
   return ret;
}



void init_cma3k()
{
   output_float(pin_scl);
   output_float(pin_sda);
   write_cma3k(RSTR,0X02);
   write_cma3k(RSTR,0X0A);
   write_cma3k(RSTR,0X04);      //RESET ASIC
   write_cma3k(CTRL,0b10000011);// INIT CONF
}


Last edited by ivan on Mon Nov 16, 2009 1:13 pm; edited 6 times in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group