nopnop2002 / esp-idf-ssd1306

SSD1306/SH1106 Driver for esp-idf
MIT License
264 stars 74 forks source link

I don't know any Init cmd and I have any CMD_STREAM or DATA_STREAM question #20

Closed WangShuoran closed 2 years ago

WangShuoran commented 2 years ago

When in your code: https://github.com/nopnop2002/esp-idf-ssd1306/blob/cfd3ba8fd35009ce9edc890594bde5112678f68f/components/ssd1306/ssd1306_i2c.c#L62

    i2c_master_write_byte(cmd, OLED_CMD_SET_DISPLAY_OFFSET, true);      // D3
    i2c_master_write_byte(cmd, 0x00, true);
    i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);    // 40
    //i2c_master_write_byte(cmd, OLED_CMD_SET_SEGMENT_REMAP, true);     // A1
    if (dev->_flip) {
        i2c_master_write_byte(cmd, OLED_CMD_SET_SEGMENT_REMAP_0, true);     // A0
    } else {
        i2c_master_write_byte(cmd, OLED_CMD_SET_SEGMENT_REMAP_1, true);     // A1
    }
    i2c_master_write_byte(cmd, OLED_CMD_SET_COM_SCAN_MODE, true);       // C8
    i2c_master_write_byte(cmd, OLED_CMD_SET_DISPLAY_CLK_DIV, true);     // D5
    i2c_master_write_byte(cmd, 0x80, true);
    i2c_master_write_byte(cmd, OLED_CMD_SET_COM_PIN_MAP, true);         // DA

I think when OLED_CONTROL_BYTE_DATA_STREAM those below code will can not happen, because 0x40 let ssd1306 think those below code is data instead of cmd.

Can you give me any answer about this.

When you use ssd1306, your code let any OLED_CONTROL_BYTE_DATA_STREAM and OLED_CONTROL_BYTE_CMD_STREAM in your i2c function begin and end. Those cmd is necessary?

And I have another question, when I see the ssd1306 manual, the D/C# flag begin with Control Byte, I want to know this cmd is legal?

image
#define OLED_CONTROL_BYTE_CMD_SINGLE    0x80
#define OLED_CONTROL_BYTE_CMD_STREAM    0x00
#define OLED_CONTROL_BYTE_DATA_SINGLE   0xC0
#define OLED_CONTROL_BYTE_DATA_STREAM   0x40
nopnop2002 commented 2 years ago

Thank you for reporting.

It was OLED_CMD_SET_DISPLAY_START_LINE instead of OLED_CONTROL_BYTE_DATA_STREAM. Both are 0x40.

    //i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);  // 40
    i2c_master_write_byte(cmd, OLED_CMD_SET_DISPLAY_START_LINE, true);  // 40

I think when OLED_CONTROL_BYTE_DATA_STREAM those below code will can not happen, because 0x40 let ssd1306 think those below code is data instead of cmd.

/* Control byte for i2c
Co : bit 8 : Continuation Bit
 * 1 = no-continuation (only one byte to follow)
 * 0 = the controller should expect a stream of bytes.
D/C# : bit 7 : Data/Command Select bit
 * 1 = the next byte or byte stream will be Data.
 * 0 = a Command byte or byte stream will be coming up next.
 Bits 6-0 will be all zeros.
Usage:
0x80 : Single Command byte
0x00 : Command Stream
0xC0 : Single Data byte
0x40 : Data Stream
*/

If it starts with OLED_CONTROL_BYTE_CMD_STREAM(0x00), up to i2c_master_stop is treated as command. Even if there is 0x40 in the middle, it is not a control byte but a command.

i2c_master_start(cmd); // i2c Start Condition
i2c_master_write_byte(cmd, (dev->_address << 1) | I2C_MASTER_WRITE, true);
i2c_master_write_byte(cmd, 0x00, true); // start command stream
i2c_master_write_byte(cmd, 0x00, true); // command
i2c_master_write_byte(cmd, 0x40, true); // command
i2c_master_write_byte(cmd, 0x80, true); // command
i2c_master_write_byte(cmd, 0xc0, true); // command
i2c_master_stop(cmd); // i2c Stop Condition

If it starts with OLED_CONTROL_BYTE_DATA_STREAM(0x40), up to i2c_master_stop is treated as data. Even if there is 0x40 in the middle, it is not a control byte but a data.

i2c_master_start(cmd); // i2c Start Condition
i2c_master_write_byte(cmd, (dev->_address << 1) | I2C_MASTER_WRITE, true);
i2c_master_write_byte(cmd, 0x40, true); // start data strem
i2c_master_write_byte(cmd, 0x00, true); // data
i2c_master_write_byte(cmd, 0x40, true); // data
i2c_master_write_byte(cmd, 0x80, true); // data
i2c_master_write_byte(cmd, 0xc0, true); // data
i2c_master_stop(cmd); // i2c Stop Condition
image

The datasheet says:

After the transmission of the slave address, either the control byte or the data byte may be sent across
the SDA. A control byte mainly consists of Co and D/C# bits following by six “0” ‘s.
a. If the Co bit is set as logic “0”, the transmission of the following information will contain
data bytes only.
b. The D/C# bit determines the next data byte is acted as a command or a data. If the D/C# bit is
set to logic “0”, it defines the following data byte as a command. If the D/C# bit is set to
logic “1”, it defines the following data byte as a data which will be stored at the GDDRAM.
The GDDRAM column address pointer will be increased by one automatically after each
data write.

I don't think you can send multiple commands and multiple data at the same time like in this example.

WangShuoran commented 2 years ago

I know, so can I think your code in my question. https://github.com/nopnop2002/esp-idf-ssd1306/blob/cfd3ba8fd35009ce9edc890594bde5112678f68f/components/ssd1306/ssd1306_i2c.c#L62 This cmd is useless, because of your answer, the OLED_CONTROL_BYTE_DATA_STREAM have no happen.

Sorry about I didn't say my point in a polite way

nopnop2002 commented 2 years ago

This cmd is useless, because of your answer, the OLED_CONTROL_BYTE_DATA_STREAM have no happen.

No

i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);

This command is valid. This command has the same functionality as OLED_CMD_SET_DISPLAY_START_LINE.

WangShuoran commented 2 years ago

I know, Thank you for your answer patiently.