Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2c write fail incorrect #1

Open
Deous opened this issue May 27, 2018 · 2 comments
Open

i2c write fail incorrect #1

Deous opened this issue May 27, 2018 · 2 comments

Comments

@Deous
Copy link

Deous commented May 27, 2018

This part of code makes some identical oleds not to work

	if (!i2c->write(address)) {
		i2c->stop();
		ESP_LOGE("oled", "OLED I2C bus not responding.");
		goto oled_init_fail;
	}

It is caused by I2C::write()

// return: true - ACK; false - NACK
bool I2C::write(uint8_t data)
{
    uint8_t ibit;
    bool ret;

    for (ibit = 0; ibit < 8; ++ibit)
    {
        if (data & 0x80)
            _SDA1;
        else
            _SDA0;
        _DELAY;
        _SCL1;
        _DELAY;
        data = data << 1;
        _SCL0;
    }
    _SDA1;
    _DELAY;
    _SCL1;
    _DELAY;
    ret = (_SDAX == 0);  // it is always 0 on some oleds
    _SCL0;
    _DELAY;

    return ret;
}

If we ignore __SDAX==0 and return true all works fine. Might related be some incorrect protocol response

@imxieyi
Copy link
Owner

imxieyi commented May 27, 2018

According to the datasheet of SSD1306, ACK (SDAout=0) should be sent after every byte. I guess some of the panels only connects SDAin without SDAout to SDA pin. In this situation of cause ACK should be ignored. However I don't think it's a good idea to always ignore ACK no matter whether SDAout is connected. For details please refer to pp.19 of the datasheet.

@Deous
Copy link
Author

Deous commented Jun 4, 2018

The interesting thing is - those oleds somehow work fine on Arduino libraries - particularly Adafruit.
I haven't looked deeper there because it is heavy wrapped but they do some kind of oled test before switching it on. Maybe something should be done in our case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants