This is my code to write data:
- static esp_err_t ssd1306_write_data(void *sensor, const uint8_t *const data_buf,
- const uint8_t data_len) {
- ssd1306_dev_t *sens = (ssd1306_dev_t *)sensor;
- esp_err_t ret;
- i2c_cmd_handle_t cmd = i2c_cmd_link_create();
- ret = i2c_master_start(cmd);
- assert(ESP_OK == ret);
- ret = i2c_master_write_byte(cmd, sens->dev_addr | I2C_MASTER_WRITE, true);
- assert(ESP_OK == ret);
- ret = i2c_master_write_byte(cmd, 0x40, true);
- assert(ESP_OK == ret);
- ret = i2c_master_write(cmd, data_buf, data_len, true);
- assert(ESP_OK == ret);
- ret = i2c_master_stop(cmd);
- assert(ESP_OK == ret);
- ret = i2c_master_cmd_begin(sens->bus, cmd, 1000 / portTICK_PERIOD_MS);
- i2c_cmd_link_delete(cmd);
- return ret;
- }
- void SSD1306_init(void) {
- esp_err_t ret;
- ssd1306 = ssd1306_create(I2C_MASTER_NUM, SSD1306_ADDR);
- TEST_ASSERT_NOT_NULL_MESSAGE(ssd1306, "SSD1306 create returned NULL");
- ssd1306_write_cmd(ssd1306, 0xAE);
- ssd1306_write_cmd(ssd1306, 0x00);
- ssd1306_write_cmd(ssd1306, 0x10);
- ssd1306_write_cmd(ssd1306, 0x40);
- ssd1306_write_cmd(ssd1306, 0xB0);
- ssd1306_write_cmd(ssd1306, 0x81);
- ssd1306_write_cmd(ssd1306, 0xFF);
- ssd1306_write_cmd(ssd1306, 0xA1);
- ssd1306_write_cmd(ssd1306, 0xA6);
- ssd1306_write_cmd(ssd1306, 0xA8);
- ssd1306_write_cmd(ssd1306, 0x3F);
- ssd1306_write_cmd(ssd1306, 0xC8);
- ssd1306_write_cmd(ssd1306, 0xD3);
- ssd1306_write_cmd(ssd1306, 0x00);
- ssd1306_write_cmd(ssd1306, 0xD5);
- ssd1306_write_cmd(ssd1306, 0x80);
- ssd1306_write_cmd(ssd1306, 0xD8);
- ssd1306_write_cmd(ssd1306, 0x05);
- ssd1306_write_cmd(ssd1306, 0xD9);
- ssd1306_write_cmd(ssd1306, 0xF1);
- ssd1306_write_cmd(ssd1306, 0xDA);
- ssd1306_write_cmd(ssd1306, 0x12);
- ssd1306_write_cmd(ssd1306, 0xDB);
- ssd1306_write_cmd(ssd1306, 0x30);
- ssd1306_write_cmd(ssd1306, 0x8D);
- ssd1306_write_cmd(ssd1306, 0x14);
- ssd1306_write_cmd(ssd1306, 0xAF);
- ssd1306_clean();
- ESP_LOGI(TAG, "Finish init %s", TAG);
- }