From 699e46521fc945897250eeab3f70ed6d83526165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 27 Feb 2020 19:43:14 +0100 Subject: [PATCH] oled_ssd1306: fix writing to display --- lib/oled_ssd1306.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/oled_ssd1306.c b/lib/oled_ssd1306.c index 8c9003f..331460d 100644 --- a/lib/oled_ssd1306.c +++ b/lib/oled_ssd1306.c @@ -127,13 +127,12 @@ void oled_ssd1306_display(const uint8_t* display_data, uint16_t display_length) if (I2C_MASTER_RC_NONE != i2c_master_select_slave(OLED_SSD1306_I2C, oled_ssd1306_slave_addr, false, true)) { // select OLED display return; } - const uint8_t oled_data[] = { - 0x40, // control byte: continuous (multiple byes), data - }; - if (I2C_MASTER_RC_NONE != i2c_master_write(OLED_SSD1306_I2C, oled_data, LENGTH(oled_data))) { // send data header - return; + uint8_t oled_data[display_length + 1]; // we have to copy the data because we need to send a single block since i2c_master_write sends a stop + oled_data[0] = 0x40; // control byte: continuous (multiple byes), data + for (uint16_t i = 0; i < display_length; i++) { + oled_data[i + 1] = display_data[i]; } - if (I2C_MASTER_RC_NONE != i2c_master_write(OLED_SSD1306_I2C, display_data, display_length)) { // send template picture to display + if (I2C_MASTER_RC_NONE != i2c_master_write(OLED_SSD1306_I2C, oled_data, display_length + 1)) { // send data header return; } i2c_master_stop(OLED_SSD1306_I2C); // send stop condition