Jim Cooke
/
Hat_Board_v5_1
Slight Mod
Fork of Hat_Board_v5 by
Diff: main.cpp
- Revision:
- 3:8334f137c151
- Parent:
- 2:3a8cd127b72a
- Child:
- 4:e9df42113893
--- a/main.cpp Thu Mar 20 09:49:36 2014 +0000 +++ b/main.cpp Fri Mar 21 01:13:05 2014 +0000 @@ -2,8 +2,6 @@ //Goal of program: read and output data from LIS3DH accelerometer //Started with Si_4088_PC working program: able to get data from Si1142 on new hat board -// Check PS_ADC_COUNTER. It's probably wrong. - #include "mbed.h" #include "SI_LIS.h" #include <time.h> @@ -18,17 +16,21 @@ char rx_data[4]; char accel_data[6]; char temp_val; -short int temp_dataX; // short int: 16 bits. This allows easy negative results -short int temp_dataY; // short int: 16 bits. This allows easy negative results -short int temp_dataZ; // short int: 16 bits. This allows easy negative results +short int dataX; // short int: 16 bits. This allows easy negative results +short int dataY; // short int: 16 bits. This allows easy negative results +short int dataZ; // short int: 16 bits. This allows easy negative results float t_msec; +float dataX_fl; +float dataY_fl; +float dataZ_fl; +float accel_fl; int main() { - unsigned char LowB_IR,HighB_IR,LowB_660,HighB_660; + // To test: Block data update (CTRL_REG4); 1.25 KHz data; low power vs normal power myled4 = 0; // ODD: if this line not included, there is a compiler "internal error" - pc.baud(230400); + pc.baud(460800); Init_Accel(); // starts LIS3DH restart(); // starts Si1142 @@ -38,44 +40,33 @@ while(1) { if(!int_pin) { - - myled3 = !myled3; // LED on mbed, to follow along - t.reset(); t.start(); write_reg(IRQ_STATUS,0x04); // clear the interrupt. read_reg2(PS1_DATA0); - LowB_IR = rx_data[0]; - HighB_IR = rx_data[1]; - - LowB_660 = rx_data[2]; - HighB_660 = rx_data[3]; - - reading_IR = (HighB_IR * 256) + LowB_IR; - reading_660 = (HighB_660 * 256) + LowB_660; + reading_IR = rx_data[1] << 8 | rx_data[0]; + reading_660 = rx_data[3] << 8 | rx_data[1]; pc.printf ("%d, %d, ", reading_IR,reading_660); Get_Accel_Reg_6 (0x28); - temp_dataX = (accel_data[1] * 256) + accel_data[0]; - pc.printf ("%d, ",temp_dataX); - - temp_dataY = (accel_data[3] * 256) + accel_data[2]; - pc.printf ("%d, ",temp_dataY); - - temp_dataZ = (accel_data[5] * 256) + accel_data[4]; - pc.printf ("%d, ",temp_dataZ); + dataX = accel_data[1] << 8 | accel_data[0]; + dataX_fl = (float) dataX; + dataY = accel_data[3] << 8 | accel_data[2]; + dataY_fl = (float) dataY; + dataZ = accel_data[5] << 8 | accel_data[4]; + dataZ_fl = (float) dataZ; + accel_fl = sqrt( (dataX_fl*dataX_fl) + (dataY_fl*dataY_fl) + (dataZ_fl*dataZ_fl) ); + pc.printf ("%6.0f ",accel_fl); t.stop(); t_msec = t.read() * 1000; - printf("%4.1f msec\n", t_msec); + printf("%6.3f msec\n", t_msec); } } - - } /* Notes on RJ-45: Pin 1: Vcc Pin 2: GND Pin 3: SDA > 9 on 4088