Statistics: Posted by Guest — Mon Feb 06, 2017 11:16 am
Code:
void mpu_sleep(void)
{
uint8 add=104; //0x68 MPU-6050 address
uint8 reg_add=107; //register I'm trying to write
uint8 data=8; //data I'm trying to write
uint8 ack; //ack signal from slave
i2c_master_gpio_init();
i2c_master_start();
i2c_master_writeByte(add);
ack = i2c_master_getAck();
if(ack){
os_printf("located mpu6050 \n \r");
i2c_master_writeByte(reg_add+128);//address and 8-bit set high for write operation
ack=i2c_master_getAck();
if(ack) {
os_printf("pointing to register reg_add and bit 8 set to high (+128) \n \r");
i2c_master_writeByte(data); //data
ack=i2c_master_getAck();
if(ack){
os_printf("sucessfully wrote the data to reg_addr \n \r");
i2c_master_stop();
os_printf("acc disable sucessfully \n \r");
}
//debug messages
else{
i2c_master_stop();
os_printf("failed to write data to address \n \r");}
}
else {
i2c_master_stop();
os_printf("failed to point to address \n \r");}
}
else{
i2c_master_stop();
os_printf("failed to locate the device \n \r");
}
}
Statistics: Posted by Joaohcca — Tue Jan 24, 2017 1:10 am