I2C Wire.write(x) issue

I was trying out the I2C When i noticed that Wire.write(x) always returns a 1. According to the docs it returns the following.

0: success
1: data too long to fit in transmit buffer
2: received NACK on transmit of address
3: received NACK on transmit of data
4: other error

Here is my code.

unsigned char x;
unsigned char i2cStatus=0;

void setup()
{

Serial1.begin(115200);
Serial1.println("Booted 0.1");

Wire.begin(); // join i2c bus

for(x=0;x<255;x++)
{
    Wire.beginTransmission(x); // transmit to device #44 (0x2c)
    i2cStatus = Wire.write(0xa5);             // Just send it out so i can see it on scope
    Wire.endTransmission(true);

    Serial1.print("i2S staus[");
    Serial1.print(x);
    Serial1.print("]=");
    Serial1.println(i2cStatus);
    
    delay(100);
    
}

}

I believe that table is technically for the endTransmission() method, which only currently returns 0 or 4.

beginTransmission() and write() don’t actually do what they say as far as putting data on the I2C bus, it’s all done in endTransmission();

I submitted an issue about this a couple days ago actually:
https://github.com/spark/core-firmware/issues/63

Don’t forget to add pull up resistors on SDA and SCL, or you won’t see anything :wink:

Thanks, will check out what endTransmission() gives.

“Don’t forget to add pull up resistors on SDA and SCL, or you won’t see anything” - @BDub

Since my I2C experiments did see data without the pull ups - can someone run me through when these are needed with the core?

When the I2C device you attach to the core does not have any pull up resistors :wink: Your’s did have a 4.7k on each line.

@bdub Just FYI, I’m fixing that bug you linked as part of my I2C overhaul. :smile:

@bdub - Awesome, thanks :slight_smile:

Awexome @timb, I didn’t have time to look into sorting it all out, so I just “backlogged” it :wink: