John Scharf
/
Hat_Board_v5
accel now workin
Fork of Hat_Board_Test by
Diff: SI_LIS.cpp
- Revision:
- 2:3a8cd127b72a
- Parent:
- 1:2efeed26d93a
- Child:
- 3:8334f137c151
--- a/SI_LIS.cpp Thu Mar 20 09:03:12 2014 +0000 +++ b/SI_LIS.cpp Thu Mar 20 09:49:36 2014 +0000 @@ -123,13 +123,29 @@ i2c.write((IR_ADDRESS << 1) & 0xFE, tx, 2); } -void Init_Accel (char Reg_Num, char Reg_Val) +void Init_Accel () { char data[2]; + char Reg_Num; + char Reg_Val; + + Reg_Num = 0x20; // CTRL_REG1 + Reg_Val = 0x57; // Nib 1 of 0101: Normal mode, 100 Hz; Nib 2 of 0111: Normal mode, XYZ enabled + data[0] = Reg_Num; //register to be written to data[1] = Reg_Val; //data + i2c.write((LIS_Addr << 1) & 0xFE, data, 2); + 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 + data[0] = Reg_Num; //register to be written to + data[1] = Reg_Val; //data i2c.write((LIS_Addr << 1) & 0xFE, data, 2); + + wait(0.050); // Delay needed? } void Get_Accel_Register (char Reg_Num) @@ -144,29 +160,12 @@ accel_data[0] = data; } -void Get_Accel_Register_2 (char Reg_Num) // Read 2 registers -/* -In order to read multiple bytes, it is necessary to assert the most significant bit of the subaddress -field. In other words, SUB(7) must be equal to 1 while SUB(6-0) represents the -address of first register to be read. -*/ -{ - char reg; - reg = Reg_Num | 0x80; // set bit 7 high - i2c.write((LIS_Addr << 1) & 0xFE, ®, 1); - i2c.read((LIS_Addr << 1) | 0x01, accel_2_data, 2); -} - void Get_Accel_Reg_6 (char Reg_Num) // Read 6 registers { char reg; - reg = Reg_Num | 0x80; // set bit 7 high + reg = Reg_Num | 0x80; // set bit 7 high to enable burst read i2c.write((LIS_Addr << 1) & 0xFE, ®, 1); i2c.read((LIS_Addr << 1) | 0x01, accel_data, 6); } -void i2c_start() // also set by photodiode setup/reset -{ - i2c.frequency(400000); -}