Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. void readXYZ(int16_t *x_val, int16_t *y_val, int16_t *z_val){
  2.     uint8_t x0 = 0;
  3.     uint16_t x1 = 0;
  4.     uint8_t y0 = 0;
  5.     uint16_t y1 = 0;
  6.     uint8_t z0 = 0;
  7.     uint16_t z1 = 0;
  8.    
  9.     int16_t x = 0;
  10.     int16_t y = 0;
  11.     int16_t z = 0;
  12.    
  13.     //read X-Axis
  14.     x0 = readRegister(0x80 | 0x32);
  15.     x1 = readRegister(0x80 | 0x33);
  16.    
  17.     //read Y-Axis
  18.     y0 = readRegister(0x80 | 0x34);
  19.     y1 = readRegister(0x80 | 0x35);
  20.    
  21.     //read Z-Axis
  22.     z0 = readRegister(0x80 | 0x36);
  23.     z1 = readRegister(0x80 | 0x37);
  24.    
  25.     //convert in milli-G [4.0mg/LSB] in +/- 16g mode @ full-res
  26.     x = (int16_t)((x1 << 8) | x0);
  27.     y = (int16_t)((y1 << 8) | y0);
  28.     z = (int16_t)((z1 << 8) | z0);
  29.    
  30.     *x_val = x * 4;
  31.     *y_val = y * 4;
  32.     *z_val = z * 4;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement