I've set the SDA on GPIO5 and SCL on GIPO0 on i2c_master.h (Board pins D1 and D3).
From what I understood studying the protocol, in order to write to a register I should :
1- put the 8-bit address for the slave (in my case my mpu-6050) .
2 - put the 7-bit address fot the slave register and set bit 8 high for write operation.
3 - put the 8-bit data to the i2c bus to write on the slave.
4- Send the stop signal.
In between steps I should check the ack from slave in order to proceed.
In the code bellow I'm trying to write data
Code: Select all
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");
}
}
what could I be missing?
Did I get something wrong from studying the protocol?
I can build my application but it won't execute as I expected using nonos SDK v2.0.0
Thank you for your time to read the post, any suggestions are welcome.
PS: I've test the sensor module with my arduino using one example from the arduino library and it work as expected, which indicates is not a faulty module