Jim Cooke
/
Hat_Board_v5_1
Slight Mod
Fork of Hat_Board_v5 by
main.cpp
- Committer:
- drnow
- Date:
- 2014-03-20
- Revision:
- 1:2efeed26d93a
- Parent:
- 0:34bad5aca893
- Child:
- 2:3a8cd127b72a
File content as of revision 1:2efeed26d93a:
//Hat Board Test by James Cooke 3/18/2014 //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> DigitalOut myled3(LED3); DigitalOut myled4(LED4); Serial pc(USBTX,USBRX); DigitalIn int_pin(p8); Timer t; int reading_IR,reading_660,LSB,MSB; char rx_data[4]; char accel_2_data[2]; 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 /* From AccelWaveForms In Loop: */ int main() { unsigned char LowB_IR,HighB_IR,LowB_660,HighB_660; char Reg_Val = 0x00; char Reg_Num; myled4 = 0; // ODD: if this line not included, there is a compiler "internal error" pc.baud(230400); i2c_start(); //sets i2c bus at 400,000. Also set by photodiode setup/reset Reg_Num = 0x20; // CTRL_REG1 Reg_Val = 0x57; // Nib 1 of 0101: Normal mode, 100 Hz; Nib 2 of 0111: Normal mode, XYZ enabled Init_Accel (Reg_Num, Reg_Val); wait(0.050); // Delay needed, or 2nd write doesn't work Reg_Num = 0x21; // CTRL_REG2 Reg_Val = 0xA0; // 7-6 10: Normal filter mode; 5-4 10: Cut off freq; 3-0 0000: bypass interrupts // High-pass filter bits 5-4: @ 100 Hz: 00 - 2Hz 01 - 1Hz 10- 0.5Hz 11- 0.2Hz Init_Accel (Reg_Num, Reg_Val); wait(0.050); // Delay needed? pc.printf ("Hello\n"); Get_Accel_Register (0x0F); pc.printf ("I am: %x",accel_data[0]); //in hex while (1) { Get_Accel_Reg_6 (0x28); LSB = accel_data[0]; MSB = accel_data[1]; temp_dataX = (MSB * 256) + LSB; pc.printf ("%d, ",temp_dataX); LSB = accel_data[2]; MSB = accel_data[3]; temp_dataY = (MSB * 256) + LSB; pc.printf ("%d, ",temp_dataY); LSB = accel_data[4]; MSB = accel_data[5]; temp_dataZ = (MSB * 256) + LSB; pc.printf ("%d\n",temp_dataZ); wait(0.02); } /* restart(); wait_ms(30); command (PS_AUTO); //start measuring wait (0.5); 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; pc.printf ("%d,%d\n", reading_IR,reading_660); } } */ } /* Notes on RJ-45: Pin 1: Vcc Pin 2: GND Pin 3: SDA > 9 on 4088 Pin 4: SCL >> 10 on 4088 Pin 6: INT > 8 on 4088 Bluetooth: Tx on 4088: Pin 37 >> RX Rx on 4088: Pin 31 >> TX PC COMM port on Square board: 12 */