-->
Page 1 of 3

V1.04/ESP-01: I2C, first tests

PostPosted: Sun Nov 01, 2015 2:17 pm
by matherp
Hi

I've tried the i2c commands and although it isn't working it is not looking too bad.

I'm using a SALEAE logic analyser to view the bus.

Here is my program to read the time from a DS1321 with comments on what I'm seeing:

Code: Select alllet address = 104
let numchars = 1
let nsecs = 0
i2c.begin(address) 'this works nicely address sent out correctly
i2c.write(0) 'this is a problem, I need to send out the data-value 0 but the command takes a string
' I can't create a string with a single 0 value. "" creates and empty string.
i2c.end() 'OK
i2c.requestfrom(address,numchars) ' seems OK read address set correctly
nsecs = i2c.read() ' this looks like the data line is being held low rather than being pulled high by the resistor
' but difficult to tell as the read address sent is wrong but should still be valid, correct number of clocks sent
print nsecs


The big issue for testing further is not being able to send a zero as the starting address for the read

Are you using zero terminated strings or strings with the length in the first byte?

This is important because with i2c we need to read and write zeroes. I would prefer the read to be just a single byte into a numerical variable

so a read of 5 bytes would be:

b1=i2c.read()
b2=i2c.read()
...

rgds

Peter

Re: V1.04/ESP-01: I2C, first tests

PostPosted: Sun Nov 01, 2015 2:44 pm
by matherp
Also a question.

Have you implemented this functionality (taken from the Arduino docs?

"As of Arduino 1.0.1, endTransmission() accepts a boolean argument changing its behavior for compatibility with certain I2C devices.

If true, endTransmission() sends a stop message after transmission, releasing the I2C bus.

If false, endTransmission() sends a restart message after transmission. The bus will not be released, which prevents another master device from transmitting between messages. This allows one master device to send multiple transmissions while in control."

Re: V1.04/ESP-01: I2C, first tests

PostPosted: Sun Nov 01, 2015 3:01 pm
by Mmiscool
I don't think I implemented any of that.

The arduino code to to manage the i2c in esp8266 basic

currently looks like this.

If you have any suggestions or tweaks you would like to make let me know.

Code: Select all  if (FunctionName == "i2c.begin")
  {
    i2cPinNo = Param0.toInt();
    MyOut = "";
    Wire.beginTransmission(i2cPinNo);
  }
  if (FunctionName == "i2c.write")       MyOut =  String(Wire.write(Param0.c_str()));
  if (FunctionName == "i2c.end")         MyOut =  String(Wire.endTransmission());
  if (FunctionName == "i2c.requestfrom")
  {
    i2cPinNo = Param0.toInt();
    byte i2cParamB = Param1.toInt();
    MyOut =  String(Wire.requestFrom(i2cPinNo, i2cParamB));
  }
  if (FunctionName == "i2c.available")   MyOut =  String(Wire.available());
  if (FunctionName == "i2c.read")        MyOut =  String(Wire.read());

Re: V1.04/ESP-01: I2C, first tests

PostPosted: Sun Nov 01, 2015 5:43 pm
by matherp
please change:

if (FunctionName == "i2c.write") MyOut = String(Wire.write(Param0.c_str()));

to:

if (FunctionName == "i2c.write") MyOut = String(Wire.write(Param0.to_Int()));

and I'll have another go