ESP8266 Developer Zone The Official ESP8266 Forum 2017-02-06T11:16:35+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=3287 2017-02-06T11:16:35+08:00 2017-02-06T11:16:35+08:00 https://bbs.espressif.com:443/viewtopic.php?t=3287&p=11244#p11244 <![CDATA[Re: Little help using i2c API]]> i2c_master_start(); is the line at fault. Your program is correct, but the I2C library implements dummy clock cycles when you start the master using this function, and what happens is some devices get confused because of dummy clocks. This should not happen, but does seem to happen with a lot of devices.
You can get into the I2C driver code and check it out whether it suits your accelerometer or not. The I2C driver code is very, very simple. Check it out once, and modify as needed. :)
You can find the C file in driver directory of SDK.

Statistics: Posted by Guest — Mon Feb 06, 2017 11:16 am


]]>
2017-01-24T01:10:06+08:00 2017-01-24T01:10:06+08:00 https://bbs.espressif.com:443/viewtopic.php?t=3287&p=11174#p11174 <![CDATA[Little help using i2c API]]> 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:

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

Statistics: Posted by Joaohcca — Tue Jan 24, 2017 1:10 am


]]>