Read data from an ADIS16355 IMU and write it to the USB port.

Dependencies:   mbed

Committer:
yahugh
Date:
Wed Aug 10 21:50:36 2011 +0000
Revision:
0:c6ee363ac724
initial release, still has some problems but might be of interest to others regardless

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yahugh 0:c6ee363ac724 1 //
yahugh 0:c6ee363ac724 2 // main.cpp
yahugh 0:c6ee363ac724 3 //
yahugh 0:c6ee363ac724 4 // Container class for mbed-based ADIS16355 IMU data acquisition system
yahugh 0:c6ee363ac724 5 //
yahugh 0:c6ee363ac724 6 // copyright 2010 Hugh Shane
yahugh 0:c6ee363ac724 7 //
yahugh 0:c6ee363ac724 8 #include "mbed.h"
yahugh 0:c6ee363ac724 9 #include "imu-spi.h"
yahugh 0:c6ee363ac724 10 #include "usb-serial.h"
yahugh 0:c6ee363ac724 11
yahugh 0:c6ee363ac724 12 int main() {
yahugh 0:c6ee363ac724 13 DigitalOut diag_led(LED1);
yahugh 0:c6ee363ac724 14 ImuSpi imu;
yahugh 0:c6ee363ac724 15 usb_serial_init();
yahugh 0:c6ee363ac724 16 char* imubuffer;
yahugh 0:c6ee363ac724 17 bool overflow;
yahugh 0:c6ee363ac724 18 Timer timer;
yahugh 0:c6ee363ac724 19 timer.start();
yahugh 0:c6ee363ac724 20 int now, last = 0, elapsed;
yahugh 0:c6ee363ac724 21 int nbytes = 12;
yahugh 0:c6ee363ac724 22
yahugh 0:c6ee363ac724 23 while (1) {
yahugh 0:c6ee363ac724 24
yahugh 0:c6ee363ac724 25 // acquire the IMU data
yahugh 0:c6ee363ac724 26 while (!imu.IsDataReady()) {} // wait for the IMU data-ready signal
yahugh 0:c6ee363ac724 27 now = timer.read_us(); // grab the elapsed time in microseconds
yahugh 0:c6ee363ac724 28 elapsed = now - last;
yahugh 0:c6ee363ac724 29 last = now;
yahugh 0:c6ee363ac724 30 imu.BurstRead(); // read the IMU output data registers
yahugh 0:c6ee363ac724 31 imubuffer = (char*)imu.GetBufferReadPtr(); // get a pointer to the IMU output data
yahugh 0:c6ee363ac724 32
yahugh 0:c6ee363ac724 33 // transmit a data packet on the USB serial port
yahugh 0:c6ee363ac724 34 overflow = usb_serial_putc(0x55); // start of packet
yahugh 0:c6ee363ac724 35 overflow = usb_serial_putc((uint8_t)elapsed); // time marker, just the lower bits
yahugh 0:c6ee363ac724 36
yahugh 0:c6ee363ac724 37 for (int i = 0; i < nbytes; i++) {
yahugh 0:c6ee363ac724 38 overflow = usb_serial_putc(*imubuffer++); // IMU data
yahugh 0:c6ee363ac724 39 }
yahugh 0:c6ee363ac724 40
yahugh 0:c6ee363ac724 41 overflow = usb_serial_putc(0xAA); // end of packet
yahugh 0:c6ee363ac724 42
yahugh 0:c6ee363ac724 43 // diagnostic LED
yahugh 0:c6ee363ac724 44 if (overflow)
yahugh 0:c6ee363ac724 45 diag_led = 1;
yahugh 0:c6ee363ac724 46 else
yahugh 0:c6ee363ac724 47 diag_led = 0;
yahugh 0:c6ee363ac724 48
yahugh 0:c6ee363ac724 49 }
yahugh 0:c6ee363ac724 50
yahugh 0:c6ee363ac724 51 }