void l3gd20h_write(char reg, char data) { twi_start(); twi_send_address(L3GD20H::ADDRW); //write twi_send_data(reg); twi_send_data(data); twi_stop(); }
void lsm303_write(char reg, char data) { twi_start(); twi_send_address(LSM303::ADDRW); //write twi_send_data(reg); twi_send_data(data); twi_stop(); }
void lps25h_init() { // 0xB0 = 0b10110000 // PD = 1 (active mode); ODR = 011 (12.5 Hz pressure & temperature output data rate) twi_start(); twi_send_address(LPS25H::ADDRW); //write twi_send_data(LPS25H::CTRL_REG1); twi_send_data(0xB0); twi_stop(); }
uint32_t md25_get_motor_encoder(uint8_t motor) { uint32_t enc_val; uint32_t temp_data; if(motor == MD25_MOTOR1) { twi_send_buffer[0] = MD25_REGISTER_ENC1A; } else { twi_send_buffer[0] = MD25_REGISTER_ENC2A; } twi_master_set_ready(); twi_send_data(MD25_TWI_ADRESS, 1); twi_receive_data(MD25_TWI_ADRESS, 4); temp_data = twi_receive_buffer[0]; enc_val = (temp_data << 24); temp_data = twi_receive_buffer[1]; enc_val |= (temp_data << 16); temp_data = twi_receive_buffer[2]; enc_val |= (temp_data << 8); enc_val |= (uint32_t)(twi_receive_buffer[3]); return enc_val; }
void mpu9150_read_acceleration(acceleration_t* acceleration_vector) { uint8_t temp_data; twi_send_buffer[0] = MPU9150_REGISTER_ACCEL_XOUT_H; twi_master_set_ready(); twi_send_data(MPU9150_TWI_ADDRESS, 1); twi_receive_data(MPU9150_TWI_ADDRESS, 6); temp_data = twi_receive_buffer[0]; acceleration_vector->x = (uint16_t)(temp_data << 8); temp_data = twi_receive_buffer[1]; acceleration_vector->x = (uint16_t)(acceleration_vector->x | temp_data); temp_data = twi_receive_buffer[2]; acceleration_vector->y = (uint16_t)(temp_data << 8); temp_data = twi_receive_buffer[3]; acceleration_vector->y = (uint16_t)(acceleration_vector->y | temp_data); temp_data = twi_receive_buffer[4]; acceleration_vector->z = (uint16_t)(temp_data << 8); temp_data = twi_receive_buffer[5]; acceleration_vector->z = (uint16_t)(acceleration_vector->z | temp_data); acceleration_vector->z = -acceleration_vector->z; }
void mpu9150_read_angularvelocity(angularvelocity_t* angularvelocity) { uint8_t temp_data; twi_send_buffer[0] = MPU9150_REGISTER_GYRO_XOUT_H; twi_master_set_ready(); twi_send_data(MPU9150_TWI_ADDRESS, 1); twi_receive_data(MPU9150_TWI_ADDRESS, 6); temp_data = twi_receive_buffer[0]; angularvelocity->x = (uint16_t)(temp_data << 8); temp_data = twi_receive_buffer[1]; angularvelocity->x = (uint16_t)(angularvelocity->x | temp_data); temp_data = twi_receive_buffer[2]; angularvelocity->y = (uint16_t)(temp_data << 8); temp_data = twi_receive_buffer[3]; angularvelocity->y = (uint16_t)(angularvelocity->y | temp_data); temp_data = twi_receive_buffer[4]; angularvelocity->z = (uint16_t)(temp_data << 8); temp_data = twi_receive_buffer[5]; angularvelocity->z = (uint16_t)(angularvelocity->z | temp_data); }
/* *** FUNCTION DEFINITIONS ************************************************** */ void md25_set_speed(int8_t motor1, int8_t motor2) { twi_send_buffer[0] = MD25_REGISTER_MOTOR1_SPEED; twi_send_buffer[1] = motor1; twi_send_buffer[2] = motor2; twi_master_set_ready(); twi_send_data(MD25_TWI_ADRESS, 3); }
char lsm303_whoami() { char a; twi_start(); twi_send_address(LSM303::ADDRW); //write twi_send_data(LSM303::WHO_AM_I); //WHOAMI twi_start(); twi_send_address(LSM303::ADDRR); //read twi_read_data(&a, 0); twi_stop(); return a; }
int32_t lps25h_read() { char xl, l, h; twi_start(); twi_send_address(LPS25H::ADDRW); twi_send_data(LPS25H::PRESS_OUT_XL|(1<<7)); twi_start(); twi_send_address(LPS25H::ADDRR); //read twi_read_data(&xl, 1); twi_read_data(&l, 1); twi_read_data(&h, 0); twi_stop(); return ((int32_t)h << 16) | ((int32_t)l << 8) | xl; }
int16_t mpu9150_read_angularvelocity_z(void) { uint8_t temp_data; int16_t rotation_z; twi_send_buffer[0] = MPU9150_REGISTER_GYRO_ZOUT_H; twi_master_set_ready(); twi_send_data(MPU9150_TWI_ADDRESS, 1); twi_receive_data(MPU9150_TWI_ADDRESS, 2); temp_data = twi_receive_buffer[0]; rotation_z = (uint16_t)(temp_data << 8); temp_data = twi_receive_buffer[1]; rotation_z = (uint16_t)(rotation_z | temp_data); return rotation_z; }
void l3gd20h_read(int16_t *x, int16_t *y, int16_t *z) { char xl, xh, yl, yh, zl, zh; twi_start(); twi_send_address(L3GD20H::ADDRW); twi_send_data(L3GD20H::OUT_X_L|(1<<7)); twi_start(); twi_send_address(L3GD20H::ADDRR); //read twi_read_data(&xl, 1); twi_read_data(&xh, 1); twi_read_data(&yl, 1); twi_read_data(&yh, 1); twi_read_data(&zl, 1); twi_read_data(&zh, 0); twi_stop(); *x = (int16_t)(xh << 8 | xl); *y = (int16_t)(yh << 8 | yl); *z = (int16_t)(zh << 8 | zl); }
void lsm303_read_mag(int16_t *x, int16_t *y, int16_t *z) { char xl, xh, yl, yh, zl, zh; twi_start(); twi_send_address(LSM303::ADDRW); twi_send_data(LSM303::D_OUT_X_L_M|(1<<7)); twi_start(); twi_send_address(LSM303::ADDRR); //read twi_read_data(&xl, 1); twi_read_data(&xh, 1); twi_read_data(&yl, 1); twi_read_data(&yh, 1); twi_read_data(&zl, 1); twi_read_data(&zh, 0); twi_stop(); *x = (int16_t)(xh << 8 | xl); *y = (int16_t)(yh << 8 | yl); *z = (int16_t)(zh << 8 | zl); }