Code: Select all
void Init_IMU_SPI() {
sim.spi.qmr = 0xC380;//baudrate 258000 Hz, CPOL=1, CPHA=1,Master Mode
//Command Ram
sim.spi.qar=0x20;//first Command RAM entry
//QSPI configuration in Command RAM
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qdr=0x7D00;
sim.spi.qar = 0x0000; //select the first transmit ram entry
//Data to be sent to ADIS IMU
sim.spi.qdr = ZACCL_OUT;
sim.spi.qdr = XACCL_OUT;
sim.spi.qdr = YACCL_OUT;
sim.spi.qdr = ZGYRO_OUT;
sim.spi.qdr = XGYRO_OUT;
sim.spi.qdr = YGYRO_OUT;
sim.spi.qdr = ZMAGN_OUT;
sim.spi.qdr = XMAGN_OUT;
sim.spi.qdr = YMAGN_OUT;
sim.spi.qdr = TEMP_OUT;
sim.spi.qwr=0x5900;//wrap around mode enabled, return to 0x00 after executing 10 commands.
sim.spi.qir=0xD00F;//enable write collison, abort bus errors and clear any interrupts.
sim.spi.qdlyr=0x03FF;//user defined delays
}
Code: Select all
void Read_IMU_SPI() {
unsigned int flag;
flag=sim.spi.qir;
if((flag & 0x0001)==0x0001){
sim.spi.qar = 0x0010; //select the first receiver entry
int i = 0;
for (i = 0; i < 10; i++) {
imu_raw[i] = (unsigned int) (sim.spi.qdr);
}
}
Code: Select all
sim.spi.qdlyr = (0x03FF | 0x8000);
while (1) {
OSTimeDly(TICKS_PER_SECOND / 5);
Read_IMU_SPI();
}