DroneOS/Drivers/Source/drvHMC5883.c
///////////////////////////////////////////////////////////////////////////////
//! Reads HMC5883 device ID bytes
//! \param Magnetic field strength of X axis
//! \param Magnetic field strength of Y axis
//! \param Magnetic field strength of Z axis
//! \return dosTrue if values were red successfully
Reads HMC5883 device ID bytes
\param Magnetic field strength of X axis
\param Magnetic field strength of Y axis
\param Magnetic field strength of Z axis
\return dosTrue if values were red successfully
Reads HMC5883 device ID bytes \ param Magnetic field strength of X axis \ param Magnetic field strength of Y axis \ param Magnetic field strength of Z axis \ return dosTrue if values were red successfully
dosBool drvHMC5883ReadValues(dosWord* out_x, dosWord* out_y, dosWord* out_z)
{
	dosByte status;
	dosBool ack = dosFalse;
	dosByte retry = 3;
	do
	{   
		ack = HMC5883_I2C_Start(HMC5883_I2C, drvI2C_WRITE, drvHMC5883_BASE_ADDRESS);
	  if( ack )
	  {
			HMC5883_I2C_WriteByte(HMC5883_I2C, drvHMC5883_RA_DATAOUT_XMSB);
			HMC5883_I2C_Restart(HMC5883_I2C, drvI2C_READ, drvHMC5883_BASE_ADDRESS);
			*out_x = HMC5883_I2C_ReadByte(HMC5883_I2C, drvI2C_ACK) << 8;
			*out_x |= HMC5883_I2C_ReadByte(HMC5883_I2C, drvI2C_ACK);
			*out_y = HMC5883_I2C_ReadByte(HMC5883_I2C, drvI2C_ACK) << 8;
			*out_y |= HMC5883_I2C_ReadByte(HMC5883_I2C, drvI2C_ACK);
			*out_z = HMC5883_I2C_ReadByte(HMC5883_I2C, drvI2C_ACK) << 8;
			*out_z |= HMC5883_I2C_ReadByte(HMC5883_I2C, drvI2C_ACK);
			status = HMC5883_I2C_ReadByte(HMC5883_I2C, drvI2C_NACK);
		}
		HMC5883_I2C_Stop(HMC5883_I2C);
		retry--;
	}	while( retry > 0 && ack && (status & drvHMC5883_STATUS_RDY) == 0 );
	return ack;
}
dosBool drvHMC5883ReadValues ( dosWord * out_x , dosWord * out_y , dosWord * out_z ) { dosByte status ; dosBool ack = dosFalse ; dosByte retry = 3 ; do { ack = HMC5883_I2C_Start ( HMC5883_I2C , drvI2C_WRITE , drvHMC5883_BASE_ADDRESS ) ; if ( ack ) { HMC5883_I2C_WriteByte ( HMC5883_I2C , drvHMC5883_RA_DATAOUT_XMSB ) ; HMC5883_I2C_Restart ( HMC5883_I2C , drvI2C_READ , drvHMC5883_BASE_ADDRESS ) ; * out_x = HMC5883_I2C_ReadByte ( HMC5883_I2C , drvI2C_ACK ) << 8 ; * out_x |= HMC5883_I2C_ReadByte ( HMC5883_I2C , drvI2C_ACK ) ; * out_y = HMC5883_I2C_ReadByte ( HMC5883_I2C , drvI2C_ACK ) << 8 ; * out_y |= HMC5883_I2C_ReadByte ( HMC5883_I2C , drvI2C_ACK ) ; * out_z = HMC5883_I2C_ReadByte ( HMC5883_I2C , drvI2C_ACK ) << 8 ; * out_z |= HMC5883_I2C_ReadByte ( HMC5883_I2C , drvI2C_ACK ) ; status = HMC5883_I2C_ReadByte ( HMC5883_I2C , drvI2C_NACK ) ; } HMC5883_I2C_Stop ( HMC5883_I2C ) ; retry -- ; } while ( retry > 0 && ack && ( status & drvHMC5883_STATUS_RDY ) == 0 ) ; return ack ; }
Reads HMC5883 device ID bytes
\param Magnetic field strength of X axis
\param Magnetic field strength of Y axis
\param Magnetic field strength of Z axis
\return dosTrue if values were red successfully
Reads HMC5883 device ID bytes \ param Magnetic field strength of X axis \ param Magnetic field strength of Y axis \ param Magnetic field strength of Z axis \ return dosTrue if values were red successfully
// read X value // read Y value // read Z value // read status byte