Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. //Boolean function to test if device responds
  2. uint8_t test_connection(void){
  3. spi3_transmit_byte(0x0F); //Address of WHO_AM_I
  4. uint8_t who_am_i = spi3_receive_byte();
  5. return who_am_i == 0xD3; //0xD3 = default value of WHO_AM_I
  6. }
  7. //X-axis angular rate data. The value is expressed as two’s complement.
  8. int16_t get_x_velocity(void){
  9. spi3_transmit_byte(0x28); //address of OUT_X_L
  10. uint8_t x_low = spi3_receive_byte();
  11. spi3_transmit_byte(0x29); //address of OUT_X_H
  12. uint8_t x_high = spi3_receive_byte();
  13. return (((uint16_t)x_high) << 8) & ((uint16_t)x_low);
  14. }
  15. //Y-axis angular rate data. The value is expressed as two’s complement.
  16. int16_t get_y_velocity(void){
  17. spi3_transmit_byte(0x2A); //address of OUT_Y_L
  18. uint8_t y_low = spi3_receive_byte();
  19. spi3_transmit_byte(0x2B); //address of OUT_Y_H
  20. uint8_t y_high = spi3_receive_byte();
  21. return (((uint16_t)y_high) << 8) & ((uint16_t)y_low);
  22. }
  23. //Z-axis angular rate data. The value is expressed as two’s complement.
  24. int16_t get_z_velocity(void){
  25. spi3_transmit_byte(0x2C); //address of OUT_Z_L
  26. uint8_t z_low = spi3_receive_byte();
  27. spi3_transmit_byte(0x2D); //address of OUT_Z_H
  28. uint8_t z_high = spi3_receive_byte();
  29. return (((uint16_t)z_high) << 8) & ((uint16_t)z_low);
  30. }
  31. //no idea if temperature is signed or not. or what the unit is.
  32. int8_t get_temperature(void){
  33. spi_transmit_byte(0x26); //address of OUT_TEMP
  34. return spi3_receive_byte();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement