Error chceking
This commit is contained in:
parent
bbaf73ef6e
commit
3d9b3ee325
2 changed files with 23 additions and 5 deletions
26
MPU6050.c
26
MPU6050.c
|
@ -9,14 +9,23 @@
|
||||||
void MPU6050_Init() {
|
void MPU6050_Init() {
|
||||||
DEBUG("MPU6050_init: Initializing...");
|
DEBUG("MPU6050_init: Initializing...");
|
||||||
// Wake up MPU-6050 by writing to PWR_MGMT_1 register
|
// Wake up MPU-6050 by writing to PWR_MGMT_1 register
|
||||||
I2C_start(MPU6050_ADDR << 1 | TW_WRITE);
|
if(!I2C_start(MPU6050_ADDR << 1 | TW_WRITE)) {
|
||||||
|
DEBUG("MPU6050_init: Failed to start I2C communication");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// These two seem to be causing problems
|
// These two seem to be causing problems
|
||||||
DEBUG("MPU6050_init: Sending PWR_MGMT_1 register address");
|
DEBUG("MPU6050_init: Sending PWR_MGMT_1 register address");
|
||||||
I2C_write(MPU6050_REG_PWR_MGMT_1);
|
if(!I2C_write(MPU6050_REG_PWR_MGMT_1)) {
|
||||||
|
DEBUG("MPU6050_init: Failed to write to PWR_MGMT_1 register");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG("Writing 0x00 to PWR_MGMT_1 register");
|
DEBUG("Writing 0x00 to PWR_MGMT_1 register");
|
||||||
I2C_write(0x00); // Clear sleep mode bit
|
if(!I2C_write(0x00)) { // Clear sleep mode bit
|
||||||
|
DEBUG("MPU6050_init: Failed to write to PWR_MGMT_1 register");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG("MPU6050_init: Stopping...");
|
DEBUG("MPU6050_init: Stopping...");
|
||||||
I2C_stop();
|
I2C_stop();
|
||||||
|
@ -28,9 +37,16 @@ void MPU6050_Read_Accel(int16_t* accel_data) {
|
||||||
uint8_t buffer[6]; // Buffer to store accelerometer data
|
uint8_t buffer[6]; // Buffer to store accelerometer data
|
||||||
|
|
||||||
// Read accelerometer data starting from ACCEL_XOUT_H register
|
// Read accelerometer data starting from ACCEL_XOUT_H register
|
||||||
I2C_start(MPU6050_ADDR << 1 | TW_WRITE);
|
if(!I2C_start(MPU6050_ADDR << 1 | TW_WRITE)) {
|
||||||
|
DEBUG("MPU6050_Read_Accel: Failed to start I2C communication: %d", MPU6050_ADDR << 1 | TW_WRITE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG("MPU6050_Read_Accel: Sending ACCEL_XOUT_H register address");
|
DEBUG("MPU6050_Read_Accel: Sending ACCEL_XOUT_H register address");
|
||||||
I2C_write(MPU6050_REG_ACCEL_XOUT_H);
|
if(I2C_write(MPU6050_REG_ACCEL_XOUT_H)) {
|
||||||
|
DEBUG("MPU6050_Read_Accel: Failed to write to ACCEL_XOUT_H register");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG("MPU6050_Read_Accel: Reading accelerometer data");
|
DEBUG("MPU6050_Read_Accel: Reading accelerometer data");
|
||||||
I2C_start(MPU6050_ADDR << 1 | TW_READ);
|
I2C_start(MPU6050_ADDR << 1 | TW_READ);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# AVR Playground
|
# AVR Playground
|
||||||
|
|
||||||
|
See [AVR i2c library](https://github.com/Sovichea/avr-i2c-library).
|
||||||
|
|
||||||
[QEMU AVR Docs](https://www.qemu.org/docs/master/system/target-avr.html)
|
[QEMU AVR Docs](https://www.qemu.org/docs/master/system/target-avr.html)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
Loading…
Reference in a new issue