Hugh S / Mbed 2 deprecated imu-daq

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //
00002 // main.cpp
00003 //
00004 // Container class for mbed-based ADIS16355 IMU data acquisition system
00005 //
00006 // copyright 2010 Hugh Shane
00007 //
00008 #include "mbed.h"
00009 #include "imu-spi.h"
00010 #include "usb-serial.h"
00011 
00012 int main() {
00013     DigitalOut diag_led(LED1);          
00014     ImuSpi imu;
00015     usb_serial_init();
00016     char* imubuffer;
00017     bool overflow;
00018     Timer timer;
00019     timer.start();
00020     int now, last = 0, elapsed;
00021     int nbytes = 12;
00022      
00023     while (1) {
00024     
00025         // acquire the IMU data
00026         while (!imu.IsDataReady()) {} // wait for the IMU data-ready signal
00027         now = timer.read_us(); // grab the elapsed time in microseconds
00028         elapsed = now - last;
00029         last = now;
00030         imu.BurstRead(); // read the IMU output data registers
00031         imubuffer = (char*)imu.GetBufferReadPtr(); // get a pointer to the IMU output data
00032         
00033         // transmit a data packet on the USB serial port
00034         overflow = usb_serial_putc(0x55); // start of packet
00035         overflow = usb_serial_putc((uint8_t)elapsed); // time marker, just the lower bits
00036         
00037         for (int i = 0; i < nbytes; i++) {
00038             overflow = usb_serial_putc(*imubuffer++); // IMU data
00039         }
00040         
00041         overflow = usb_serial_putc(0xAA); // end of packet
00042 
00043         // diagnostic LED
00044         if (overflow)
00045             diag_led = 1;
00046         else
00047             diag_led = 0;
00048             
00049     }
00050 
00051 }