AnsweredAssumed Answered

ADIS16488 SPI connection using the mbed microcontroller LPC1768

Question asked by RobinUofC on Apr 4, 2014
Latest reply on Apr 10, 2014 by NevadaMark

Hi,

 

I am using the mbed MCU to interface with the 6488, trying to display gyros and accls data on the Tera terminal.

The problem for me is I did not get the right data from the registers, and the register did not update the output, as seen on the Tera screen.

FYI, the output data simply shows x_gyro=y_gyro=z_gyro=-0.02deg/s, and x_acc=y_acc=z_acc=0.0008g( apparently z_acc should be 1g, which I doubted if it actually read the register data).

Can you please help me check what might happen? I was so confused by this problem those days. Attached below is the code I did on the mbed. Thank you and I am looking forward to your reply!

 

The mbed code:

#include "mbed.h"

#include "stdio.h"

 

SPI imu(p5, p6, p7);        //set up spi interface on pins 5,6,7

DigitalOut cs(p8);      //use pin 8 as chip select

Serial pc(USBTX, USBRX);        //USB interface to host terminal

unsigned short buffer[12];    

int16_t data[6];      

float x_gyro, y_gyro, z_gyro,x_acc, y_acc, z_acc, a_gyro, b_gyro, c_gyro, a_acc, b_acc, c_acc;

int main(){

    cs = 1;

    imu.format(16,3);       //16 bit data, mode 3

    imu.frequency(1000000);  //1MHz clock rate

    cs=0;                     //select devices

    imu.write(0x8003);

    imu.write(0x8CF5);       //set sample rate at 10Hz

    cs=1;

    while(1) {

        wait_ms(500);   //power-on start-up time is 500ms

        cs=0;

        imu.write(0x8000);      //turn back to page 1

        buffer[1]=imu.write(0x1200);    //x_gyro(16bit high) However, I only used high output registers

        buffer[0]=imu.write(0x1000);    //x_gyro(16bit low)

        buffer[3]=imu.write(0x1600);    //y_gyro(16bit high)

        buffer[2]=imu.write(0x1400);    //y_gyro(16bit low)

        buffer[5]=imu.write(0x1A00);    //z_gyro(16bit high)     

        buffer[4]=imu.write(0x1800);    //z_gyro(16bit low)

        buffer[7]=imu.write(0x1E00);

        buffer[6]=imu.write(0x1C00);

        buffer[9]=imu.write(0x2200);

        buffer[8]=imu.write(0x2000);

        buffer[11]=imu.write(0x2600);

        buffer[10]=imu.write(0x2400);     //accs measurement

 

        imu.write(0x8003);  //update flash memory.However, the measurement data do not have flash

        imu.write(0x8200|0x08);

        wait_ms(375);

 

         cs=1;

        data[0]=buffer[1]; //Gyros; convert gyro registers to int16_t format

        data[1]=buffer[3];

        data[2]=buffer[5];

 

        data[3]=buffer[7]; //Accs; convert acc registers to int16_t format

        data[4]=buffer[9];

        data[5]=buffer[11];

        wait(0.1); 

 

        x_gyro=0.02*data[0];y_gyro=0.02*data[1];z_gyro= 0.02*data[2];

        x_acc=0.0008*data[3];y_acc=0.0008*data[4];z_acc= 0.0008*data[5];

        pc.printf("x_gyro= %+1.2fdeg/s\t y_gyro= %+1.2fdeg/s\t z_gyro= %+1.2fdeg/s\t x_acc= %+1.4fg\t y_acc= %+1.4fg\t z_acc= %+1.4fg\n\t",x_gyro,y_gyro,z_gyro,x_acc,y_acc,z_acc);   

    }

}

Outcomes