Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Boolean function to test if device responds
- uint8_t test_connection(void){
- spi3_transmit_byte(0x0F); //Address of WHO_AM_I
- uint8_t who_am_i = spi3_receive_byte();
- return who_am_i == 0xD3; //0xD3 = default value of WHO_AM_I
- }
- //X-axis angular rate data. The value is expressed as two’s complement.
- int16_t get_x_velocity(void){
- spi3_transmit_byte(0x28); //address of OUT_X_L
- uint8_t x_low = spi3_receive_byte();
- spi3_transmit_byte(0x29); //address of OUT_X_H
- uint8_t x_high = spi3_receive_byte();
- return (((uint16_t)x_high) << 8) & ((uint16_t)x_low);
- }
- //Y-axis angular rate data. The value is expressed as two’s complement.
- int16_t get_y_velocity(void){
- spi3_transmit_byte(0x2A); //address of OUT_Y_L
- uint8_t y_low = spi3_receive_byte();
- spi3_transmit_byte(0x2B); //address of OUT_Y_H
- uint8_t y_high = spi3_receive_byte();
- return (((uint16_t)y_high) << 8) & ((uint16_t)y_low);
- }
- //Z-axis angular rate data. The value is expressed as two’s complement.
- int16_t get_z_velocity(void){
- spi3_transmit_byte(0x2C); //address of OUT_Z_L
- uint8_t z_low = spi3_receive_byte();
- spi3_transmit_byte(0x2D); //address of OUT_Z_H
- uint8_t z_high = spi3_receive_byte();
- return (((uint16_t)z_high) << 8) & ((uint16_t)z_low);
- }
- //no idea if temperature is signed or not. or what the unit is.
- int8_t get_temperature(void){
- spi_transmit_byte(0x26); //address of OUT_TEMP
- return spi3_receive_byte();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement