I am trying to read data from an IMU (http://www.analog.com/static/imported-f ... S16488.pdf). The way this works is, netburner sends a comamnd to IMU via SPI3 and IMU responds with the corresponding data. So my code looks like.
Code: Select all
#define xahigh 0x00001E00 //command to IMU for MSB of Xaccel
#define yahigh 0x00002200 //command to IMU for MSB of Yaccel
#define zahigh 0x00002600 //command to IMU for MSB of Zaccel
void initIMUspi()
{
J2[21].function(1);//SPI3 Input
J2[22].function(1);//SPI3 Out
J2[23].function(1);//SPI3 chip select 0
J2[24].function(1);//SPI3 clock
sim1.dspi3.ctar[0]=0x7E020006; //SPI Transfer protocol
}
void readIMU()
{
sim1.dspi3.pushr=0x04FF0000|xahigh;
sim1.dspi3.pushr=0x04FF0000|yahigh;
sim1.dspi3.pushr=0x04FF0000|zahigh;
sim1.dspi3.mcr =0x81FF0000;//Starting Transfers
while(((sim1.dspi3.sr & 0x0000F000)>>12)>0){}//Waiting for transfers to complete
//reading POPR
IMU_raw[0]=(short int)sim1.dspi3.popr;
IMU_raw[1]=(short int)sim1.dspi3.popr;
IMU_raw[2]=(short int)sim1.dspi3.popr;
sim1.dspi3.mcr=0x81FF0C01;//Stop Transfers
}
Code: Select all
#define xahigh 0x00001E00
#define yahigh 0x00002200
#define zahigh 0x00002600
void initIMUspi()
{
J2[21].function(1);//SPI3 Input
J2[22].function(1);//SPI3 Out
J2[23].function(1);//SPI3 chip select 0
J2[24].function(1);//SPI3 clock
sim1.dspi3.ctar[0]=0x7E020006; //SPI Transfer protocol
}
void readIMU()
{
sim1.dspi3.pushr=0x04FF0000|xahigh;
sim1.dspi3.pushr=0x04FF0000|yahigh;
sim1.dspi3.pushr=0x04FF0000|zahigh;
sim1.dspi3.pushr=0x04FF0000|xahigh;
sim1.dspi3.pushr=0x04FF0000|yahigh;
sim1.dspi3.pushr=0x04FF0000|zahigh;
sim1.dspi3.mcr =0x81FF0000;//Starting Transfers
while(((sim1.dspi3.sr & 0x0000F000)>>12)>0){}//Waiting for transfers to complete
//reading POPR
IMU_raw[0]=(short int)sim1.dspi3.popr;
IMU_raw[1]=(short int)sim1.dspi3.popr;
IMU_raw[2]=(short int)sim1.dspi3.popr;
IMU_raw[3]=(short int)sim1.dspi3.popr;
IMU_raw[4]=(short int)sim1.dspi3.popr;
IMU_raw[5]=(short int)sim1.dspi3.popr;
sim1.dspi3.mcr=0x81FF0C01;//Stop Transfers
}
Thanks in advance,
TM