diff --git a/MPU6050.c b/MPU6050.c index 1a18994..c683b30 100644 --- a/MPU6050.c +++ b/MPU6050.c @@ -9,14 +9,23 @@ void MPU6050_Init() { DEBUG("MPU6050_init: Initializing..."); // 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 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"); - 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..."); I2C_stop(); @@ -28,9 +37,16 @@ void MPU6050_Read_Accel(int16_t* accel_data) { uint8_t buffer[6]; // Buffer to store accelerometer data // 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"); - 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"); I2C_start(MPU6050_ADDR << 1 | TW_READ); diff --git a/README.md b/README.md index 97a4116..70eb548 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # 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) ```bash