beautypg.com

PNI RM3000-F Sensor Suite User Manual

Page 44

background image

PNI Sensor Corporation

Doc #1016102 r04

RM3000-f & RM2000-f Sensor Suite User Manual

Page 44


/*************************************************************************
* Function Name : mag_sample
* Description : Sample the magnetic sensors and get measurement in
"count"
* Input : None
* Output : None
* Return : None
*************************************************************************/
void mag_sample(void)
{

unsigned char axis;


//

// change the phase and polarity to be 0/0

//

spi_1_go_0_phase_0_pol();


SPI_tom_CS_LOW();

usec_delay(1);

//Send 0xC9 on MOSI pin to initiate reading the measurement values

tom_first_byte=SPI_read_write(0xc9);

usec_delay(1);

//Read data from X-axis, Y-axis and Z-axis

for(axis=0;axis<3;axis++)

{

mag_raw[axis]=SPI_read_write(0)<<16;

usec_delay(1);

mag_raw[axis]|=SPI_read_write(0)<<8;

usec_delay(1);

mag_raw[axis]|=SPI_read_write(0);

//

//check the MSB and do sign extension if necessary

//

if(mag_raw[axis]&0x00800000)

{

mag_raw[axis]|=0xff000000;

}

}

SPI_tom_CS_HIGH();

usec_delay(1);

SPI_tom_CS_LOW();

usec_delay(1);


//

// change the phase and polarity to be 1/1

//

spi_1_go_1_phase_1_pol();

}