Ejemplo n.º 1
0
void read_full_xyz()
{
	int i;
	uint8_t data[6];
	int16_t temp[3];
	
	i2c_start();
//Add function call for i2C read setup        //	i2c_read_setup(MMA_ADDR , REG_XHI);
	i2c_read_setup(MMA_ADDR, REG_XHI);
	
// Read five bytes in repeated read mode to data array "data[6]"
	for(i = 0; i<3; i++){
		data[i] = i2c_repeated_read(0);
	}
// Read last byte ending repeated read_mode
	data[i] = i2c_repeated_read(1);
	
// save acceleration data into temp variables for all 3-axis into temp[i] array
//data type for temp[i] should be int16_t;
//index number for the data array is multiplied by 2 due to a 14-bit accel. data
	
	for(i=0; i<3; i++){
		temp[i] = (int16_t)((data[2*i]<<8) | data[2*i+1]);
	}
	// Add the following code to align accel. data in the data array for 14 bits
	acc_X = temp[0]/4;
	acc_Y = temp[1]/4;
	acc_Z = temp[2]/4;
}
void read_full_xyz()
{
	int i;
	uint8_t data[6];
	int16_t temp[3];
	
	i2c_start();
	i2c_read_setup(MMA_ADDR , REG_XHI);
	
	// Read five bytes in repeated mode
	for( i=0; i<5; i++)	{
		data[i] = i2c_repeated_read(0);
	}
	// Read last byte ending repeated mode
	data[i] = i2c_repeated_read(1);
	
	for ( i=0; i<3; i++ ) {
		temp[i] = (int16_t) ((data[2*i]<<8) | data[2*i+1]);
	}

	// Align for 14 bits
	acc_X = temp[0]/4;
	acc_Y = temp[1]/4;
	acc_Z = temp[2]/4;
}