Example #1
0
void sensorRead(imu_data *pimu_data) {

    union {
        char as_char[6];
        int16_t as_int16[3];
    } raw;

    // read and scale accelerometer values
    i2cSetAddress(ACCEL_I2C_ADDR);
    i2cReadBlock(ACCEL_DATA_BASE_ADD, raw.as_char, 6);

    pimu_data->accel[0] = raw.as_int16[0] * ACCEL_RES;
    pimu_data->accel[1] = raw.as_int16[1] * ACCEL_RES;
    pimu_data->accel[2] = raw.as_int16[2] * ACCEL_RES;

    // read and scale magnetometer values - returned as big-endien
    i2cSetAddress(MAG_I2C_ADDR);
    i2cReadBlock(MAG_DATA_BASE_ADD, raw.as_char, 6);

    pimu_data->mag[0] = (int16_t) (raw.as_char[0] << 8 | raw.as_char[1]) / MAG_SEN;
    pimu_data->mag[1] = (int16_t) (raw.as_char[4] << 8 | raw.as_char[5]) / MAG_SEN;
    pimu_data->mag[2] = (int16_t) (raw.as_char[2] << 8 | raw.as_char[3]) / MAG_SENZ;

    // read and scale gyroscope values
    i2cSetAddress(GYRO_I2C_ADDR);
    i2cReadBlock(GYRO_DATA_BASE_ADD, raw.as_char, 6);

    pimu_data->gyro[0] = raw.as_int16[0] * GYRO_RES;
    pimu_data->gyro[1] = raw.as_int16[1] * GYRO_RES;
    pimu_data->gyro[2] = raw.as_int16[2] * GYRO_RES;

//    printf("IMU data: \t%.3f\t%.3f\t%.3f", pimu_data->accel[0], pimu_data->accel[1], pimu_data->accel[2]);
//    printf("\t\t%.3f\t%.3f\t%.3f", pimu_data->mag[0], pimu_data->mag[1], pimu_data->mag[2]);
//    printf("\t\t%.3f\t%.3f\t%.3f\n", pimu_data->gyro[0], pimu_data->gyro[1], pimu_data->gyro[2]);

}
Example #2
0
/* getTemp:
 * Obtain the temperature from the DS1624 IC
 * and return the pointer to where it is stored
 */
int8_t* getTemp(void)
{
	static int8_t	temperature[2];
	
	i2cAddress(DS1624_ADDRESS, TW_WRITE);
	/* Intiate Read Temperature */
	i2cTransmit(0xAA); 	
		
	/* Receive the bytes*/
	i2cAddress(DS1624_ADDRESS, TW_READ);
	i2cReadBlock(temperature, 2);
	i2cStop();
	
	
	return temperature;
}
Example #3
0
/* serialEE_ReadBlock:
 * Read 'datasize' bytes to the array pointed to by 'data'
 * from the block_address and block of the EEPROM
 */
void serialEE_ReadBlock(uint8_t* data,
								 uint8_t	 datasize,  
								 EE_AddressStruct* EE_AddressData)
{
	
		/* Begin reading from the given address and block */
		i2cAddress( (EE_I2C_ADDRESS) 
						| (EE_BLOCKSELECT(EE_AddressData->EE_Block))
						, TW_WRITE );
#if	EE_WORD_ADDRESS == 1
		i2cTransmit((uint16_t)(EE_AddressData->EE_Address) >> 8);
#endif							
		i2cTransmit( (EE_AddressData->EE_Address) & 0xFF );

	
		/* Begin reading */
		i2cAddress( (EE_I2C_ADDRESS) 
						| (EE_BLOCKSELECT(EE_AddressData->EE_Block))
						, TW_READ );
		i2cReadBlock(data , datasize);
		i2cStop();
	
	
}